// src/db/Students/GetById.tsx
//
import { COL_USER_METAS } from '@/constants';

import { pb } from '@/lib/pb';
import type { DBStudent, Student } from '@/components/dashboard/student/type';

export async function getStudentById(id: string): Promise<Student> {
  const record = await pb
    .collection(COL_USER_METAS)
    .getOne<DBStudent>(id, { expand: 'billingAddress, helloworld', requestKey: null });

  const temp: Student = {
    id: record.id,
    name: record.name,
    email: record.email,
    quota: record.quota,
    billingAddress: record.expand.billingAddress ? record.expand.billingAddress[0] : {},
    status: record.status,
    state: record.state,
    createdAt: new Date(record.created),
    collectionId: record.collectionId,
    avatar: record.avatar,
    phone: record.phone,
    company: record.company,
    timezone: record.timezone,
    language: record.language,
    currency: record.currency,
  };

  return temp;
}
