using System;
using InABox.Core;

namespace InABox.Core.Reports
{
    [UserTracking(false)]
    public class ReportTemplate : Entity, IPersistent, IRemotable, ILicense<CoreLicense>
    {
        
        [TextBoxEditor]
        [EditorSequence(1)]
        public string Name { get; set; }

        [ComboLookupEditor(typeof(PrinterLookups), Visible = Core.Visible.Hidden, Editable = Editable.Hidden)]
        [EditorSequence(2)]
        public string PrinterName { get; set; }
        
        [NullEditor]
        public string RDL { get; set; }

        [CheckBoxEditor]
        [EditorSequence(3)]
        public bool Visible { get; set; } = true;

        [CheckBoxEditor]
        [EditorSequence(4)]
        public bool AllRecords { get; set; } = false;

        [CheckBoxEditor]
        [EditorSequence(5)]
        public bool SelectedRecords { get; set; } = true;

        [NullEditor]
        public string Script { get; set; }
        
        [NullEditor]
        public string DataModel { get; set; }
        
        [NullEditor]
        public string Section { get; set; }

        [NullEditor]
        [Obsolete("All Reports are now Fast Reports-based")]
        public bool IsRDL { get; set; } = false;

        public static readonly string DefaultScriptTemplate = @"using System;
using System.Linq;
using System.Runtime;
using InABox.Core;
using Comal.Classes;

public class Report
{{

    public {0} Model {{ get; set; }}
    public IEnumerable<String> RequiredTables {{ get; set; }}

    public bool Init()
    {{
        return true;
    }}

    public bool Populate()
    {{
        return true;
    }}

}}";
        
        private class PrinterLookups : LookupGenerator<object>
        {
            public PrinterLookups(object[] items) : base(items)
            {
                AddValue("", "No Printer Selected");
                foreach (var printer in ReportPrinters.All)
                    AddValue(printer, printer);
            }
        }
    }
}