using System;
using System.Linq.Expressions;

namespace InABox.Core
{
    [Caption("Layouts")]
    public class DigitalFormLayout : Entity, IRemotable, IPersistent, IStringAutoIncrement<DigitalFormLayout>, IOneToMany<DigitalForm>,
        ILicense<DigitalFormsLicense>
    {
        [NullEditor]
        [Obsolete("Replaced by Form")]
        public QAFormLink QAForm => InitializeField(ref _qAForm, nameof(QAForm));
        private QAFormLink _qAForm;

        [NullEditor]
        [EntityRelationship(DeleteAction.Cascade)]
        public DigitalFormLink Form => InitializeField(ref _form, nameof(Form));
        private DigitalFormLink _form;

        [EditorSequence(1)]
        [CodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
        public string Code { get; set; }

        [EditorSequence(2)]
        [TextBoxEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
        public string Description { get; set; }

        [EditorSequence(3)]
        [EnumLookupEditor(typeof(DFLayoutType), Visible = Visible.Default, Editable = Editable.Enabled)]
        public DFLayoutType Type { get; set; } = DFLayoutType.Desktop;

        [EditorSequence(4)]
        [MemoEditor(Visible = Visible.Hidden, Editable = Editable.Hidden)]
        public string Layout { get; set; }

        [EditorSequence(5)]
        [CheckBoxEditor]
        public bool Active { get; set; }

        public Expression<Func<DigitalFormLayout, string>> AutoIncrementField()
        {
            return x => x.Code;
        }

        public Filter<DigitalFormLayout> AutoIncrementFilter()
        {
            return new Filter<DigitalFormLayout>(x => x.Form.ID).IsEqualTo(Form.ID);
        }

        public string AutoIncrementPrefix() => "L";

        public string AutoIncrementFormat()
        {
            return "{0:D3}";
        }

        public IEntityDuplicator GetDuplicator()
        {
            return new EntityDuplicator<DigitalFormLayout>();
        }
    }
}