/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/authorization-code.aurora.yaml
 */
import { OAuthClientModel } from '@app/o-auth/client';
import { DataTypes } from 'sequelize';
import { BelongsTo, Column, ForeignKey, Model, Table } from 'sequelize-typescript';

@Table({
  modelName: 'OAuthAuthorizationCode',
  tableName: 'o_auth_authorization_code',
  freezeTableName: true,
  timestamps: false,
  indexes: [
    {
      fields: ['row_id'],
      unique: true,
    },
    {
      fields: ['code'],
      unique: true,
    },
    {
      fields: ['client_id'],
      unique: false,
    },
    {
      fields: ['account_id'],
      unique: false,
    },
    {
      fields: ['expires_at'],
      unique: false,
      name: 'o_auth_auth_code_expires_at',
    },
  ],
})
export class OAuthAuthorizationCodeModel extends Model<OAuthAuthorizationCodeModel> {
  @Column({
    field: 'id',
    primaryKey: true,
    allowNull: false,
    type: DataTypes.UUID,
  })
  id: string;

  @Column({
    field: 'row_id',
    autoIncrement: true,
    allowNull: false,
    type: DataTypes.BIGINT,
  })
  rowId: number;

  @Column({
    field: 'code',
    allowNull: false,
    type: DataTypes.STRING(64),
  })
  code: string;

  @ForeignKey(() => OAuthClientModel)
  @Column({
    field: 'client_id',
    allowNull: false,
    type: DataTypes.UUID,
  })
  clientId: string;

  @BelongsTo(() => OAuthClientModel, {
    constraints: false,
    foreignKey: 'client_id',
  })
  client: OAuthClientModel;

  @Column({
    field: 'account_id',
    allowNull: false,
    type: DataTypes.UUID,
  })
  accountId: string;

  @Column({
    field: 'redirect_uri',
    allowNull: false,
    type: DataTypes.STRING(2046),
  })
  redirectUri: string;

  @Column({
    field: 'scopes',
    allowNull: true,
    type: DataTypes.JSON,
  })
  scopes: any;

  @Column({
    field: 'code_challenge',
    allowNull: true,
    type: DataTypes.STRING(128),
  })
  codeChallenge: string;

  @Column({
    field: 'code_challenge_method',
    allowNull: true,
    type: DataTypes.STRING(16),
  })
  codeChallengeMethod: string;

  @Column({
    field: 'expires_at',
    allowNull: false,
    type: DataTypes.DATE,
  })
  expiresAt: string;

  @Column({
    field: 'is_used',
    allowNull: false,
    type: DataTypes.BOOLEAN,
    defaultValue: false,
  })
  isUsed: boolean;

  @Column({
    field: 'created_at',
    allowNull: true,
    type: DataTypes.DATE,
  })
  createdAt: string;

  @Column({
    field: 'updated_at',
    allowNull: true,
    type: DataTypes.DATE,
  })
  updatedAt: string;

  @Column({
    field: 'deleted_at',
    allowNull: true,
    type: DataTypes.DATE,
  })
  deletedAt: string;
}
