import { IsEntityID } from 'picsur-shared/dist/validators/entity-id.validator';
import { Column, Entity, Index, PrimaryGeneratedColumn, Unique } from 'typeorm';
import z from 'zod';

export const EUsrPreferenceSchema = z.object({
  id: IsEntityID().optional(),
  key: z.string(),
  value: z.string(),
  user_id: IsEntityID(),
});
type EUsrPreference = z.infer<typeof EUsrPreferenceSchema>;

@Entity()
@Unique(['key', 'user_id'])
export class EUsrPreferenceBackend implements EUsrPreference {
  @PrimaryGeneratedColumn('uuid')
  id?: string;

  @Index()
  @Column({ nullable: false })
  key: string;

  @Column({ nullable: false })
  value: string;

  @Index()
  @Column({ nullable: false })
  user_id: string;
}
