import type { RecordModel } from 'pocketbase';

import { dayjs } from '@/lib/dayjs';

import { defaultLessonType } from './_constants';

// import type { LessonType } from './ILessonType';

export interface LessonTypeEditFormProps {
  name: string;
  type: string;
  pos: number;
  visible: string;
}

export interface RestLessonTypeUpdateForm {
  id: string;
  data: LessonTypeEditFormProps;
}

export interface CreateForm {
  name: string;
  type: string;
  pos: number;
  visible: string;
}

export function safeAssignment(inTemp: LessonType | RecordModel): LessonType {
  const { id, name, type, pos, visible, createdAt, email, quota, status } = { ...defaultLessonType, ...inTemp };
  const oCreatedAt = dayjs(createdAt).toDate();

  const output: LessonType = {
    id,
    name,
    type,
    pos,
    visible,
    createdAt: oCreatedAt,
    email,
    quota,
    status,
  };
  return output;
}

export interface LessonType {
  id: string;
  isEmpty?: boolean;
  name: string;
  type: string;
  pos: number;
  visible: 'visible' | 'hidden';
  createdAt: Date;
  //
  // original
  // id: string;
  // name: string;
  //
  avatar?: string;
  email: string;
  phone?: string;
  quota: number;
  status: 'pending' | 'active' | 'blocked';
  // createdAt: Date;
}

export interface DBLessonType {
  id: string;
  name: string;
  type: string;
  pos: number;
  visible: 'visible' | 'hidden';
  createdAt: Date;
  created: 'string';
}

export interface Helloworld {
  id: string;
}
