export interface JobSearchProfile {
  targetRoles: string[];
  experienceLevel: string;
  mustHaveSkills: string[];
  niceToHaveSkills: string[];
  dealBreakers: string[];
  preferredWorkArrangement: string[];
  preferredLocations: string[];
  minimumSalary: string;
  industriesToTarget: string[];
  industriesToAvoid: string[];
  aboutMe: string;
  /** When set, logging in with this Basic Auth username activates this profile and its resume path. */
  basicAuthUser?: string | null;
  /** Relative (to orchestrator cwd) or absolute path to local Reactive Resume JSON; applied on profile activate. */
  resumeLocalPath?: string | null;
}

export interface SearchProfile {
  id: string;
  name: string;
  data: JobSearchProfile;
  createdAt: string;
  updatedAt: string;
}

export interface CreateSearchProfileInput {
  name: string;
  data: JobSearchProfile;
}

export interface UpdateSearchProfileInput {
  name?: string;
  data?: JobSearchProfile;
}

export interface SuitabilityAnalysis {
  roleTypeMatch: number;
  /** How well location / remote vs hybrid / on-site matches preferences (0–100). */
  workArrangementMatch?: number;
  strengths: string[];
  gaps: string[];
  suggestions: string[];
  dealBreakerHits: string[];
}

export interface ResumeProjectCatalogItem {
  id: string;
  name: string;
  description: string;
  date: string;
  isVisibleInBase: boolean;
}

export interface ResumeProjectsSettings {
  maxProjects: number;
  lockedProjectIds: string[];
  aiSelectableProjectIds: string[];
}

export type RxResumeMode = "v4" | "v5";

export const CHAT_STYLE_LANGUAGE_MODE_VALUES = [
  "manual",
  "match-resume",
] as const;

export type ChatStyleLanguageMode =
  (typeof CHAT_STYLE_LANGUAGE_MODE_VALUES)[number];

export const CHAT_STYLE_MANUAL_LANGUAGE_VALUES = [
  "english",
  "german",
  "french",
  "spanish",
] as const;

export type ChatStyleManualLanguage =
  (typeof CHAT_STYLE_MANUAL_LANGUAGE_VALUES)[number];

export const CHAT_STYLE_MANUAL_LANGUAGE_LABELS: Record<
  ChatStyleManualLanguage,
  string
> = {
  english: "English",
  german: "German",
  french: "French",
  spanish: "Spanish",
};

export interface ResumeProfile {
  basics?: {
    name?: string;
    label?: string;
    image?: string;
    email?: string;
    phone?: string;
    url?: string;
    summary?: string;
    headline?: string;
    location?: {
      address?: string;
      postalCode?: string;
      city?: string;
      countryCode?: string;
      region?: string;
    };
    profiles?: Array<{
      network?: string;
      username?: string;
      url?: string;
    }>;
  };
  sections?: {
    summary?: {
      id?: string;
      visible?: boolean;
      name?: string;
      content?: string;
    };
    skills?: {
      id?: string;
      visible?: boolean;
      name?: string;
      items?: Array<{
        id: string;
        name: string;
        description: string;
        level: number;
        keywords: string[];
        visible: boolean;
      }>;
    };
    projects?: {
      id?: string;
      visible?: boolean;
      name?: string;
      items?: Array<{
        id: string;
        name: string;
        description: string;
        date: string;
        summary: string;
        visible: boolean;
        keywords?: string[];
        url?: string;
      }>;
    };
    experience?: {
      id?: string;
      visible?: boolean;
      name?: string;
      items?: Array<{
        id: string;
        company: string;
        position: string;
        location: string;
        date: string;
        summary: string;
        visible: boolean;
      }>;
    };
    [key: string]: unknown;
  };
  [key: string]: unknown;
}

export interface ProfileStatusResponse {
  exists: boolean;
  error: string | null;
}

export interface ValidationResult {
  valid: boolean;
  message: string | null;
  status?: number | null;
}

export interface DemoInfoResponse {
  demoMode: boolean;
  resetCadenceHours: number;
  lastResetAt: string | null;
  nextResetAt: string | null;
  baselineVersion: string | null;
  baselineName: string | null;
}

export type Resolved<T> = { value: T; default: T; override: T | null };
export type ModelResolved = { value: string; override: string | null };

export interface AppSettings {
  // Typed settings (Resolved):
  jobSearchProfile: Resolved<JobSearchProfile>;
  model: Resolved<string>;
  llmProvider: Resolved<string>;
  llmBaseUrl: Resolved<string>;
  pipelineWebhookUrl: Resolved<string>;
  jobCompleteWebhookUrl: Resolved<string>;
  resumeProjects: Resolved<ResumeProjectsSettings>;
  ukvisajobsMaxJobs: Resolved<number>;
  adzunaMaxJobsPerTerm: Resolved<number>;
  gradcrackerMaxJobsPerTerm: Resolved<number>;
  startupjobsMaxJobsPerTerm: Resolved<number>;
  usajobsMaxJobsPerTerm: Resolved<number>;
  jobicyMaxJobsPerTerm: Resolved<number>;
  themuseMaxJobsPerTerm: Resolved<number>;
  joobleMaxJobsPerTerm: Resolved<number>;
  careerjetMaxJobsPerTerm: Resolved<number>;
  reedMaxJobsPerTerm: Resolved<number>;
  remoteokMaxJobsPerTerm: Resolved<number>;
  remotiveMaxJobsPerTerm: Resolved<number>;
  arbeitnowMaxJobsPerTerm: Resolved<number>;
  himalayasMaxJobsPerTerm: Resolved<number>;
  weworkremotelyMaxJobsPerTerm: Resolved<number>;
  workingnomadsMaxJobsPerTerm: Resolved<number>;
  testdevjobsMaxJobsPerTerm: Resolved<number>;
  testdevjobsMaxPages: Resolved<number>;
  builtinMaxJobsPerTerm: Resolved<number>;
  builtinMaxPagesPerTerm: Resolved<number>;
  wellfoundMaxJobsPerTerm: Resolved<number>;
  googleJobsMaxJobsPerTerm: Resolved<number>;
  fourdayweekMaxJobsPerTerm: Resolved<number>;
  qajobsboardMaxJobsPerTerm: Resolved<number>;
  arcRemoteJobsPaths: Resolved<string[]>;
  arcMaxJobsPerPath: Resolved<number>;
  leverCompanies: Resolved<string[]>;
  ashbyCompanies: Resolved<string[]>;
  greenhouseCompanies: Resolved<string[]>;
  workdayTenants: Resolved<string[]>;
  smartrecruitersCompanies: Resolved<string[]>;
  smartrecruitersMaxJobsPerCompany: Resolved<number>;
  teamtailorCompanies: Resolved<string[]>;
  huntflowTenants: Resolved<string[]>;
  factorialTenants: Resolved<string[]>;
  careersPageUrls: Resolved<string[]>;
  elutaRssLocations: Resolved<string[]>;
  elutaMaxJobsPerTerm: Resolved<number>;
  bctenetRssUrls: Resolved<string[]>;
  bctenetMaxJobsPerTerm: Resolved<number>;
  icimsTenants: Resolved<string[]>;
  icimsMaxJobsPerTenant: Resolved<number>;
  icimsMaxPagesPerSearch: Resolved<number>;
  searchTerms: Resolved<string[]>;
  workplaceTypes: Resolved<Array<"remote" | "hybrid" | "onsite">>;
  blockedCompanyKeywords: Resolved<string[]>;
  blockedCountries: Resolved<string[]>;
  scoringInstructions: Resolved<string>;
  searchCities: Resolved<string>;
  jobspyResultsWanted: Resolved<number>;
  jobspyCountryIndeed: Resolved<string>;
  showSponsorInfo: Resolved<boolean>;
  renderMarkdownInJobDescriptions: Resolved<boolean>;
  chatStyleTone: Resolved<string>;
  chatStyleFormality: Resolved<string>;
  chatStyleConstraints: Resolved<string>;
  chatStyleDoNotUse: Resolved<string>;
  chatStyleLanguageMode: Resolved<ChatStyleLanguageMode>;
  chatStyleManualLanguage: Resolved<ChatStyleManualLanguage>;
  backupEnabled: Resolved<boolean>;
  backupHour: Resolved<number>;
  backupMaxCount: Resolved<number>;
  penalizeMissingSalary: Resolved<boolean>;
  missingSalaryPenalty: Resolved<number>;
  autoSkipScoreThreshold: Resolved<number | null>;
  rxresumeMode: Resolved<RxResumeMode>;

  // Model variants (no own default, fallback to model.value):
  modelScorer: ModelResolved;
  modelTailoring: ModelResolved;
  modelProjectSelection: ModelResolved;

  // Simple strings:
  activeProfileId: string | null;
  /** JSON map of basic-auth username → search profile id when one login has multiple profiles. */
  basicAuthActiveProfileByUser: string | null;
  rxresumeBaseResumeId: string | null;
  rxresumeBaseResumeIdV4: string | null;
  rxresumeBaseResumeIdV5: string | null;
  rxresumeEmail: string | null;
  rxresumeUrl: string | null;
  /** Path to local Reactive Resume JSON (see JOBOPS_LOCAL_RESUME_PATH). */
  localResumeProfilePath: string | null;
  ukvisajobsEmail: string | null;
  adzunaAppId: string | null;
  basicAuthUser: string | null;
  usajobsUserAgent: string | null;
  themuseApiKey: string | null;
  careerjetAffid: string | null;
  careerjetReferer: string | null;
  careerjetUserIp: string | null;
  careerjetUserAgent: string | null;

  // Secret hints:
  llmApiKeyHint: string | null;
  rxresumeApiKeyHint: string | null;
  rxresumePasswordHint: string | null;
  ukvisajobsPasswordHint: string | null;
  adzunaAppKeyHint: string | null;
  basicAuthPasswordHint: string | null;
  webhookSecretHint: string | null;
  usajobsApiKeyHint: string | null;
  joobleApiKeyHint: string | null;
  reedApiKeyHint: string | null;

  // Computed:
  basicAuthActive: boolean;
  /** True when JOBOPS_LOCAL_RESUME_PATH is set on the server (not shown in UI). */
  localResumeFileConfigured: boolean;
  profileProjects: ResumeProjectCatalogItem[];
}
