import { COL_USER_METAS } from '@/constants';

import { pb } from '@/lib/pb';
import type { DBUserMeta, UserMeta } from '@/components/dashboard/user_meta/type.d';

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

  const temp: UserMeta = {
    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;
}
