export const CAPABILITY_REPOSITORY = Symbol('CAPABILITY_REPOSITORY');

export interface UserCapabilityRecord {
  id: bigint;
  accountSequence: string;
  capability: string;
  enabled: boolean;
  reason: string | null;
  disabledBy: string | null;
  disabledAt: Date | null;
  expiresAt: Date | null;
}

export interface CapabilityLogRecord {
  id: bigint;
  accountSequence: string;
  capability: string;
  action: string;
  reason: string | null;
  operatorId: string | null;
  previousValue: boolean;
  newValue: boolean;
  expiresAt: Date | null;
  createdAt: Date;
}

export interface CapabilityRepository {
  findByAccountSequence(accountSequence: string): Promise<UserCapabilityRecord[]>;

  upsert(data: {
    accountSequence: string;
    capability: string;
    enabled: boolean;
    reason?: string;
    disabledBy?: string;
    expiresAt?: Date;
  }): Promise<UserCapabilityRecord>;

  upsertWithLog(
    upsertData: {
      accountSequence: string;
      capability: string;
      enabled: boolean;
      reason?: string;
      disabledBy?: string;
      expiresAt?: Date;
    },
    logData: {
      accountSequence: string;
      capability: string;
      action: string;
      reason?: string;
      operatorId?: string;
      previousValue: boolean;
      newValue: boolean;
      expiresAt?: Date;
    },
  ): Promise<UserCapabilityRecord>;

  findExpired(): Promise<UserCapabilityRecord[]>;

  createLog(data: {
    accountSequence: string;
    capability: string;
    action: string;
    reason?: string;
    operatorId?: string;
    previousValue: boolean;
    newValue: boolean;
    expiresAt?: Date;
  }): Promise<void>;

  findLogsByAccountSequence(
    accountSequence: string,
    page: number,
    pageSize: number,
  ): Promise<{ data: CapabilityLogRecord[]; total: number }>;
}
