using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UniMarc
{
    public enum MarcRecordStatus
    {
        None,           // No record in DB (Red)
        OtherCompany,   // Found but not ours (Orange)
        MyCompany,      // Found and ours (Black/Blue etc.)
        NewFetched      // Temporary status after external search (Blue)
    }

    public class MarcBookItem
    {
        public int ListIdx { get; set; }
        public string ISBN13 { get; set; }
        public string Num { get; set; }
        public string BookName { get; set; }
        public string Author { get; set; }
        public string BookComp { get; set; }
        public string Count { get; set; }

        /// <summary>
        /// 단가(정가는 price에 있다)
        /// </summary>
        public int Pay { get; set; }
        public string Url { get; set; }
        public int MarcIdx { get; set; }
        public string DbMarc { get; set; }
        private MarcRecordStatus _status = MarcRecordStatus.None;
        public MarcRecordStatus Status
        {
            get => _status;
            set { _status = value; ApplySyncColor(); }
        }

        private string _grade = "";
        public string Grade
        {
            get => _grade;
            set { _grade = value; ApplySyncColor(); }
        }

        public string ColCheck { get; set; } = "V";
        public string User { get; set; }
        public string SaveDate { get; set; }

        public string search_book_name { get; set; }
        public string search_author { get; set; }
        public string search_book_comp { get; set; }
        public string search_description { get; set; }
        public string search_url { get; set; }

        public string category { get; set; }

        public System.Drawing.Color ForeColor { get; set; } = System.Drawing.Color.Black;
        public System.Drawing.Color BackColor { get; set; } = System.Drawing.Color.White;

        private void ApplySyncColor()
        {
            if (Status == MarcRecordStatus.None)
            {
                ForeColor = System.Drawing.Color.Red;
            }
            else if (Status == MarcRecordStatus.OtherCompany)
            {
                ForeColor = System.Drawing.Color.Orange;
            }
            else if (Status == MarcRecordStatus.NewFetched)
            {
                ForeColor = System.Drawing.Color.Blue;
            }
            else if (Status == MarcRecordStatus.MyCompany)
            {
                switch (Grade)
                {
                    case "0": // A
                        ForeColor = System.Drawing.Color.Blue;
                        break;
                    case "1": // B
                        ForeColor = System.Drawing.Color.Black;
                        break;
                    case "2": // C
                        ForeColor = System.Drawing.Color.Gray;
                        break;
                    //case "3": // D
                    //    ForeColor = System.Drawing.Color.DarkViolet;
                    //    break;
                    default:
                        ForeColor = System.Drawing.Color.DarkViolet;
                        break;
                }
            }
        }
    }
}
