using System;
using CommunityToolkit.Mvvm.ComponentModel;
using Wino.Core.Domain.Entities.Calendar;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;

namespace Wino.Calendar.ViewModels.Data;

public partial class AccountCalendarViewModel : ObservableObject, IAccountCalendar
{
    public MailAccount Account { get; }
    public AccountCalendar AccountCalendar { get; }

    public AccountCalendarViewModel(MailAccount account, AccountCalendar accountCalendar)
    {
        Account = account;
        AccountCalendar = accountCalendar;

        IsChecked = accountCalendar.IsExtended;
    }

    [ObservableProperty]
    private bool _isChecked;

    partial void OnIsCheckedChanged(bool value) => IsExtended = value;

    public string Name
    {
        get => AccountCalendar.Name;
        set => SetProperty(AccountCalendar.Name, value, AccountCalendar, (u, n) => u.Name = n);
    }

    public string TextColorHex
    {
        get => AccountCalendar.TextColorHex;
        set => SetProperty(AccountCalendar.TextColorHex, value, AccountCalendar, (u, t) => u.TextColorHex = t);
    }

    public string BackgroundColorHex
    {
        get => AccountCalendar.BackgroundColorHex;
        set => SetProperty(AccountCalendar.BackgroundColorHex, value, AccountCalendar, (u, b) => u.BackgroundColorHex = b);
    }

    public bool IsExtended
    {
        get => AccountCalendar.IsExtended;
        set => SetProperty(AccountCalendar.IsExtended, value, AccountCalendar, (u, i) => u.IsExtended = i);
    }

    public bool IsPrimary
    {
        get => AccountCalendar.IsPrimary;
        set => SetProperty(AccountCalendar.IsPrimary, value, AccountCalendar, (u, i) => u.IsPrimary = i);
    }

    public bool IsSynchronizationEnabled
    {
        get => AccountCalendar.IsSynchronizationEnabled;
        set => SetProperty(AccountCalendar.IsSynchronizationEnabled, value, AccountCalendar, (u, i) => u.IsSynchronizationEnabled = i);
    }

    public Guid AccountId
    {
        get => AccountCalendar.AccountId;
        set => SetProperty(AccountCalendar.AccountId, value, AccountCalendar, (u, a) => u.AccountId = a);
    }

    public string RemoteCalendarId
    {
        get => AccountCalendar.RemoteCalendarId;
        set => SetProperty(AccountCalendar.RemoteCalendarId, value, AccountCalendar, (u, r) => u.RemoteCalendarId = r);
    }

    public CalendarItemShowAs DefaultShowAs
    {
        get => AccountCalendar.DefaultShowAs;
        set => SetProperty(AccountCalendar.DefaultShowAs, value, AccountCalendar, (u, s) => u.DefaultShowAs = s);
    }
    public Guid Id { get => ((IAccountCalendar)AccountCalendar).Id; set => ((IAccountCalendar)AccountCalendar).Id = value; }
    public MailAccount MailAccount
    {
        get => AccountCalendar.MailAccount ?? Account;
        set => AccountCalendar.MailAccount = value;
    }
}
