import 'package:flutter/material.dart';

enum ScheduleSourceType { manual, imported, agentGenerated }

enum ScheduleStatus { active, completed, canceled, archived }

class ScheduleItemModel {
  final String id;
  final String title;
  final String? description;
  final DateTime startAt;
  final DateTime? endAt;
  final String timezone;
  final ScheduleMetadata? metadata;
  final ScheduleSourceType sourceType;
  final ScheduleStatus status;
  final DateTime createdAt;

  ScheduleItemModel({
    required this.id,
    required this.title,
    this.description,
    required this.startAt,
    this.endAt,
    this.timezone = 'Asia/Shanghai',
    this.metadata,
    this.sourceType = ScheduleSourceType.manual,
    this.status = ScheduleStatus.active,
    DateTime? createdAt,
  }) : createdAt = createdAt ?? DateTime.now();

  ScheduleItemModel copyWith({
    String? id,
    String? title,
    String? description,
    DateTime? startAt,
    DateTime? endAt,
    String? timezone,
    ScheduleMetadata? metadata,
    ScheduleSourceType? sourceType,
    ScheduleStatus? status,
    DateTime? createdAt,
  }) {
    return ScheduleItemModel(
      id: id ?? this.id,
      title: title ?? this.title,
      description: description ?? this.description,
      startAt: startAt ?? this.startAt,
      endAt: endAt ?? this.endAt,
      timezone: timezone ?? this.timezone,
      metadata: metadata ?? this.metadata,
      sourceType: sourceType ?? this.sourceType,
      status: status ?? this.status,
      createdAt: createdAt ?? this.createdAt,
    );
  }
}

class ScheduleMetadata {
  final String? color;
  final String? location;
  final String? notes;
  final List<Attachment>? attachments;

  ScheduleMetadata({this.color, this.location, this.notes, this.attachments});

  ScheduleMetadata copyWith({
    String? color,
    String? location,
    String? notes,
    List<Attachment>? attachments,
  }) {
    return ScheduleMetadata(
      color: color ?? this.color,
      location: location ?? this.location,
      notes: notes ?? this.notes,
      attachments: attachments ?? this.attachments,
    );
  }
}

class Attachment {
  final String name;
  final String? url;
  final String? content;
  final String type;

  Attachment({
    required this.name,
    this.url,
    this.content,
    this.type = 'document',
  });
}

const defaultColors = [
  Color(0xFF3B82F6),
  Color(0xFF8B5CF6),
  Color(0xFF10B981),
  Color(0xFFF59E0B),
  Color(0xFFEF4444),
];
