import { Model } from '@nozbe/watermelondb';
import { field, date, children } from '@nozbe/watermelondb/decorators';
import { Associations } from '@nozbe/watermelondb/Model';
import { Priority, Repeat, Reminder } from '@/types';

export default class Subtask extends Model {
  static table = 'subtasks';

  static associations: Associations = {
    subtasks: { type: 'has_many', foreignKey: 'parent_subtask_id' },
  };

  @field('task_id') taskId!: string;
  @field('parent_subtask_id') parentSubtaskId!: string | null;
  @field('category_id') categoryId!: string;
  @field('tags') tags!: string;
  @field('title') title!: string;
  @field('description') description!: string;
  @field('priority') priority!: Priority;
  @field('completed') completed!: boolean;
  @field('due_date') dueDate!: number;
  @field('due_time') dueTime!: string;
  @field('end_time') endTime!: string;
  @field('all_day') allDay!: boolean;
  @field('repeat') repeat!: Repeat;
  @field('repeat_interval') repeatInterval!: number;
  @field('repeat_days') repeatDays!: string;
  @field('series_id') seriesId!: string;
  @field('reminder') reminder!: Reminder;
  @field('reminders') reminders!: string;
  @field('assignee_id') assigneeId!: string | null;
  @field('order') order!: number;
  @date('created_at') createdAt!: Date;
  @date('updated_at') updatedAt!: Date;

  @children('subtasks') subtasks!: any;
}