/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/credential.aurora.yaml
 */
import { OAuthCredentialGrantTypeEnum } from '@api/graphql';
import { IamAccountDto } from '@api/iam/account';
import { OAuthAccessTokenDto } from '@api/o-auth/access-token';
import { OAuthRefreshTokenDto } from '@api/o-auth/refresh-token';
import { ApiProperty } from '@nestjs/swagger';

export class OAuthCredentialDto {
  @ApiProperty({
    type: String,
    description:
      'Unique identifier for the credential log entry. UUID v4 format, generated automatically on creation. Primary key.',
  })
  id: string;

  @ApiProperty({
    type: Number,
    description:
      'Auto-incrementing row identifier. Used for internal ordering and as a numeric alternative to UUID. Useful for chronological audit queries (ORDER BY rowId DESC LIMIT N is faster than ORDER BY createdAt DESC).',
  })
  rowId: number;

  @ApiProperty({
    enum: OAuthCredentialGrantTypeEnum,
    description:
      'OAuth2 grant type used in this issuance. PASSWORD = Resource Owner Password Credentials Grant (RFC 6749 §4.3). REFRESH_TOKEN = Refresh Token Grant (RFC 6749 §6). AUTHORIZATION_CODE is reserved for future Authorization Code Grant support; not used in the current MVP. Indexed for filtering audit queries by grant type.',
  })
  grantType: OAuthCredentialGrantTypeEnum;

  @ApiProperty({
    type: String,
    description:
      'Reference to the IamAccount whose credentials produced this issuance. Indexed for "all logins for this account" forensic queries. Many-to-one because a single account can have many issuance events over time.',
    example: '2416bff4-0667-5c51-bfa8-728f9a07454f',
  })
  accountId: string;

  @ApiProperty({
    type: () => IamAccountDto,
    description: 'IamAccount [input here api field description]',
  })
  account?: IamAccountDto;

  @ApiProperty({
    type: String,
    description:
      'Foreign key to the OAuthAccessToken row created by this issuance. One-to-one because each issuance creates exactly one access token. Nullable for safety (in degraded paths where access token persistence might fail after credential is logged), though current flow always persists both.',
    example: 'b3e0958b-f617-5cf6-820e-c555fec6dfbf',
  })
  accessTokenId?: string;

  @ApiProperty({
    type: () => OAuthAccessTokenDto,
    description:
      'Foreign key to the OAuthAccessToken row created by this issuance. One-to-one because each issuance creates exactly one access token. Nullable for safety (in degraded paths where access token persistence might fail after credential is logged), though current flow always persists both.',
  })
  accessToken?: OAuthAccessTokenDto;

  @ApiProperty({
    type: String,
    description:
      'Foreign key to the OAuthRefreshToken row created by this issuance. One-to-one. Nullable because future grant types may issue access tokens without refresh tokens (e.g., Client Credentials Grant), and to allow degraded paths.',
    example: 'f6899e77-2fe0-510b-81fa-1dc45bf17fc9',
  })
  refreshTokenId?: string;

  @ApiProperty({
    type: () => OAuthRefreshTokenDto,
    description:
      'Foreign key to the OAuthRefreshToken row created by this issuance. One-to-one. Nullable because future grant types may issue access tokens without refresh tokens (e.g., Client Credentials Grant), and to allow degraded paths.',
  })
  refreshToken?: OAuthRefreshTokenDto;

  @ApiProperty({
    type: String,
    description:
      'IP address of the client that sent the POST /api/oauth/token request. Stored as a string (not as inet) to keep cross-DB portability and to allow IPv6 representations. Maximum 45 characters covers IPv6 (max 39 chars) plus zone id suffix.',
  })
  ipAddress?: string;

  @ApiProperty({
    type: String,
    description:
      'User-Agent header sent with the token request. Truncated to 255 characters if longer. Nullable because some clients (curl, internal services) may not send it. Useful in forensics to identify the device or library origin of an issuance.',
  })
  userAgent?: string;

  @ApiProperty({
    type: String,
    description:
      'Timestamp when the credential row was created. Equivalent to the moment the token was issued. Indexed for time-range audit queries and for the retention purge job.',
  })
  createdAt?: string;

  @ApiProperty({
    type: String,
    description:
      "Timestamp when the credential row was last updated. Credential rows are typically write-once; this column is maintained by Aurora's standard timestamp lifecycle.",
  })
  updatedAt?: string;

  @ApiProperty({
    type: String,
    description:
      'Soft-delete timestamp. NULL means active row. The retention job uses hard DELETE (not soft) for storage efficiency, but the column exists to allow ad-hoc soft-deletes by operators if needed before the retention window.',
  })
  deletedAt?: string;
}
