import { Column, HasMany, Model, Table } from 'sequelize-typescript';
import { Paciente } from './paciente.unid-saude.model';
import { Atendimento } from './atendimento.model';
import { IsEmail, IsString, Matches, MaxLength, MinLength } from 'class-validator';

@Table({tableName: 'unid-saude'})
export class UnidSaude extends Model {
  
  @Column
  nomeInstituicao: string;

  @Column
  cnes: string;

  @Column
  @IsEmail()
  email: string;

  @Column
  @IsString()
  @MinLength(4)
  @MaxLength(20)
  @Matches(/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/, {
    message: 'password too weak',
  })
  senha: string;

  @Column
  cidade: string;
  
  @Column
  uf: string;

  @Column
  createdAt: Date;

  @Column
  updatedAt: Date;

  @HasMany(() => Paciente)
  paciente: Paciente[];

  @HasMany(() => Atendimento)
  atendimento: Atendimento[];
}