/** Google Calendar OAuth — public client config. Token exchange is on accounts.betterseqta.org. */

const HARDCODED_GOOGLE_OAUTH_CLIENT_ID =
  "270834969641-f6t7jtpu6j0cemse8updj3rkos7nl0hf.apps.googleusercontent.com";

const envClientId =
  typeof __GOOGLE_OAUTH_CLIENT_ID__ !== "undefined" ? __GOOGLE_OAUTH_CLIENT_ID__ : "";

export const GOOGLE_OAUTH_CLIENT_ID: string =
  envClientId.trim() || HARDCODED_GOOGLE_OAUTH_CLIENT_ID.trim();

export const ACCOUNTS_BASE = "https://accounts.betterseqta.org";

export const GOOGLE_CALENDAR_OAUTH_CALLBACK = `${ACCOUNTS_BASE}/auth/google/calendar/callback`;
export const GOOGLE_CALENDAR_TOKEN_URL = `${ACCOUNTS_BASE}/api/bsplus/google/calendar/token`;
export const GOOGLE_CALENDAR_REFRESH_URL = `${ACCOUNTS_BASE}/api/bsplus/google/calendar/refresh`;

/** App-owned secondary calendar only — cannot read or modify the user's other calendars. */
export const GOOGLE_CALENDAR_SCOPE = "https://www.googleapis.com/auth/calendar.app.created";

export const GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
export const GOOGLE_CALENDAR_API = "https://www.googleapis.com/calendar/v3";

export const BSPLUS_GOOGLE_CALENDAR_NAME = "BetterSEQTA+ Timetable";
export const BSPLUS_GOOGLE_CALENDAR_DESCRIPTION =
  "School timetable lessons synced by the BetterSEQTA+ extension.";

export const BSPLUS_GOOGLE_CALENDAR_EVENT_PROP = "bsplusSeqtaKey";

export const GOOGLE_CALENDAR_SYNC_WEEKS = 12;
export const GOOGLE_CALENDAR_SYNC_WEEKS_MIN = 1;
export const GOOGLE_CALENDAR_SYNC_WEEKS_MAX = 52;

export function isGoogleCalendarConfigured(): boolean {
  return GOOGLE_OAUTH_CLIENT_ID.length > 0;
}

export const GOOGLE_CALENDAR_ACCOUNTS_NOT_READY_HINT =
  "Google Calendar connect requires accounts.betterseqta.org — see docs/GOOGLE_CALENDAR_ACCOUNTS_CALLBACK.md";

export function googleOAuthRedirectUriHint(): string {
  return `Authorized redirect URI in Google Cloud Console must be: ${GOOGLE_CALENDAR_OAUTH_CALLBACK}`;
}
