import { isObject } from '../../utils/types'
import { Category, isCategory } from '../../assets/category'

type Announcement = {
    id: number,
    userId: number,
    name: string,
    category: Category,
    bestBy: string,
    address: string,
    lng: number,
    lat: number,
    description: string | null,
    src: string | null,
    metro: string,
    trashId: number | null,
    bookedBy: number,
}

type AnnouncementResponse = Omit<Announcement, 'userId' | 'bestBy' | 'bookedBy' | 'lat' | 'lng'> & {
    user_id: Announcement['userId'],
    best_by: Announcement['bestBy'],
    longtitude: Announcement['lng'],
    latitude: Announcement['lat'],
    booked_by: Announcement['bookedBy'],
}

const isAnnouncementResponse = (obj: unknown): obj is AnnouncementResponse => (
    isObject(obj, {
        'id': 'number',
        'user_id': 'number',
        'name': 'string',
        'category': isCategory,
        'best_by': 'string',
        'address': 'string',
        'longtitude': 'number',
        'latitude': 'number',
        'description': 'string',
        'src': 'string?',
        'metro': 'string',
        'trashId': 'number?',
        'booked_by': 'number',
    })
)

export type {
    Announcement,
    AnnouncementResponse,
}

export {
    isAnnouncementResponse,
}
