export type AppConfig = {
  port: number;
  sessionSecret: string;
  sessionMaxAgeMs: number;
  trustProxy: boolean;
  cookieSecure: boolean;
  cookieSameSite: "strict" | "lax" | "none" | boolean;
  /**
   * 仅本地调试：为 true 时登录不访问 AD/LDAP，任意非空用户名+密码即成功。
   * 上线务必删除或设为 false。
   */
  skipLdapAuthForDebug?: boolean;
  /**
   * 浏览器访问 DataEase 前端时使用的「对外」根地址（无尾斜杠），用于把相对 boardUrl
   * 拼成 iframe 的完整 URL。应与用户打开的门户同源（经 nginx 的 80/443），例如
   * http://192.168.0.235；不要填 http://127.0.0.1:8100（远程用户会连到自己本机）。
   * nginx 反代到本机 8100 的 upstream 仍单独写在 nginx 里，与此项含义不同。
   */
  dataEasePublicBase: string;
};

export type LdapTlsOptions = {
  rejectUnauthorized?: boolean;
} | null;

export type LdapConfig = {
  url: string;
  bindDN: string;
  bindPassword: string;
  searchBase: string;
  searchFilter: string;
  tlsOptions: LdapTlsOptions;
};

/** 全局 page 清单（人工维护） */
export type PageDef = {
  id: string;
  title: string;
  boardUrl: string;
  /** 相对 public/board 的封面图，如 images/01.png */
  image: string;
};

export type PagesConfig = {
  pages: PageDef[];
};

/** 场景引用的 page（只引用 pageId + staytime） */
export type ScenarioPageRef = {
  pageId: string;
  /** 本页在轮播中的停留时间（秒） */
  staytime: number;
};

/** 运行时展开后的 page（由 PageDef + staytime 组合得到） */
export type ScenarioPage = {
  id: string;
  title: string;
  boardUrl: string;
  /** 本页在轮播中的停留时间（秒） */
  staytime: number;
};

export type Scenario = {
  id: string;
  name: string;
  /** 相对 public/board 的封面图，如 images/01.png */
  image: string;
  pages: ScenarioPage[];
};

export type ScenarioCategory = {
  id: string;
  name: string;
  scenarios: Scenario[];
};

export type ScenariosConfig = {
  categories: ScenarioCategory[];
};

/** system 场景配置（开发人员维护，不可被用户修改） */
export type SystemScenario = {
  id: string;
  name: string;
  image: string;
  pages: ScenarioPageRef[];
};

export type SystemScenarioCategory = {
  id: string;
  name: string;
  scenarios: SystemScenario[];
};

export type SystemScenariosConfig = {
  categories: SystemScenarioCategory[];
};

/** user 场景配置（按用户隔离，用户可新增/删除） */
export type UserScenario = {
  id: string;
  name: string;
  image: string;
  pages: ScenarioPageRef[];
  createdAtMs: number;
};

export type UserScenariosConfig = {
  users: Record<
    string,
    {
      scenarios: UserScenario[];
    }
  >;
};

/** 单条出运/计划（来自 ShipmentReport 等） */
export type WarehousePlanEntry = {
  datestr: string;
  eventstr: string;
  note_a?: string;
  note_b?: string;
  event_status?: string;
  event_src?: string;
  event_to?: string;
};

/** SQL Server 连接（与 mssql 包 config 字段对齐） */
export type SqlServerConfig = {
  user: string;
  password: string;
  server: string;
  port?: number;
  database: string;
  options?: {
    encrypt?: boolean;
    trustServerCertificate?: boolean;
    enableArithAbort?: boolean;
  };
};

/** 单条可执行数据源 */
export type DataSrcEntry = {
  /** 业务 id，供代码或 API 引用 */
  id: string;
  /** T-SQL，使用 @参数名；参数由调用方传入 */
  sql: string;
};

export type DataSrcConfig = {
  sources: DataSrcEntry[];
};
