/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/refresh-token.aurora.yaml
 */
import { OAuthAccessTokenModel } from '@app/o-auth/access-token';
import { DataTypes } from 'sequelize';
import { BelongsTo, Column, ForeignKey, Model, Table } from 'sequelize-typescript';

@Table({
  modelName: 'OAuthRefreshToken',
  tableName: 'o_auth_refresh_token',
  freezeTableName: true,
  timestamps: false,
  indexes: [
    {
      fields: ['row_id'],
      unique: true,
    },
    {
      fields: ['access_token_id'],
      unique: false,
    },
  ],
})
export class OAuthRefreshTokenModel extends Model<OAuthRefreshTokenModel> {
  @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;

  @ForeignKey(() => OAuthAccessTokenModel)
  @Column({
    field: 'access_token_id',
    allowNull: false,
    type: DataTypes.UUID,
  })
  accessTokenId: string;

  @BelongsTo(() => OAuthAccessTokenModel, {
    constraints: false,
    foreignKey: 'access_token_id',
  })
  accessToken: OAuthAccessTokenModel;

  @Column({
    field: 'token',
    allowNull: false,
    type: DataTypes.TEXT,
  })
  token: string;

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

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

  @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;
}
