using Khaemhat.Core.Tables;
using Khaemhat.Fiscal.Abstractions;
namespace Khaemhat.Web.Tables;
/// A group of fields of a tab of the company profile.
/// The text key of the title, under CompanyTables.Profile.Groups.
/// The icon.
/// The fields.
public sealed record ProfileGroup(string Key, string Icon, IReadOnlyList Fields);
/// A tab of the company profile.
/// The id in the address (?scheda=fiscale).
/// The icon.
/// The groups.
public sealed record ProfileTab(string Id, string Icon, IReadOnlyList Groups);
/// The tabs of the company profile (SPEC ยง11.1, mockup 075).
public static class ProfileLayout
{
/// The tabs, in order.
public static IReadOnlyList Tabs { get; } =
[
new("societa", "building",
[
new("Company", "building",
[
new(nameof(CompanyProfile.LegalName)) { Required = true, Span = 12, MaxLength = 200 },
new(nameof(CompanyProfile.FiscalName)) { Span = 12, MaxLength = 200 },
new(nameof(CompanyProfile.ReaOffice), TableFieldKind.Code) { MaxLength = 2, Span = 3 },
new(nameof(CompanyProfile.ReaNumber), TableFieldKind.Code) { MaxLength = 20, Span = 3 },
new(nameof(CompanyProfile.ShareCapital), TableFieldKind.Number) { Decimals = 2, Min = 0, Span = 6 },
new(nameof(CompanyProfile.Shareholders), TableFieldKind.Choice) { Values = ["SU", "SM"] },
new(nameof(CompanyProfile.LiquidationStatus), TableFieldKind.Choice) { Values = ["LN", "LS"] },
]),
new("Address", "pin",
[
new(nameof(CompanyProfile.Address)) { Span = 9 },
new(nameof(CompanyProfile.StreetNumber)) { Span = 3, MaxLength = 10 },
new(nameof(CompanyProfile.PostalCode), TableFieldKind.Code) { Span = 3, MaxLength = 10 },
new(nameof(CompanyProfile.City)) { Span = 6 },
new(nameof(CompanyProfile.ProvinceCode), TableFieldKind.Code) { Span = 3, MaxLength = 2 },
new(nameof(CompanyProfile.AddressCountry), TableFieldKind.Lookup) { Lookup = typeof(Country), ByCode = true },
new(nameof(CompanyProfile.Phone)),
new(nameof(CompanyProfile.Email)),
new(nameof(CompanyProfile.Pec)),
new(nameof(CompanyProfile.Website)) { Span = 12 },
]),
]),
new("fiscale", "file-check",
[
new("Tax", "file-check",
[
new(nameof(CompanyProfile.Country), TableFieldKind.Lookup) { Lookup = typeof(Country), ByCode = true, Required = true },
new(nameof(CompanyProfile.CurrencyCode), TableFieldKind.Lookup) { Lookup = typeof(Currency), ByCode = true, Required = true },
new(nameof(CompanyProfile.VatNumber), TableFieldKind.Code) { MaxLength = 30 },
new(nameof(CompanyProfile.TaxCode), TableFieldKind.Code) { MaxLength = 16 },
new(nameof(CompanyProfile.TaxRegime), TableFieldKind.CodeList) { CodeList = TaxRegimes, Required = true, Span = 12 },
new(nameof(CompanyProfile.RecipientCode), TableFieldKind.Code) { MaxLength = 7 },
]),
]),
new("banche", "coins",
[
new("Bank", "coins",
[
new(nameof(CompanyProfile.DefaultBankAccountId), TableFieldKind.Lookup) { Lookup = typeof(BankAccount), Span = 12 },
]),
]),
new("stampa", "printer",
[
new("Print", "printer",
[
new(nameof(CompanyProfile.FooterNotes)) { Span = 12, Rows = 4, MaxLength = 1000 },
]),
]),
new("esercizi", "calendar",
[
new("Vat", "calendar",
[
new(nameof(CompanyProfile.FiscalYearStartMonth), TableFieldKind.Number) { Min = 1, Max = 12, Required = true, Span = 4 },
new(nameof(CompanyProfile.VatPeriodicity), TableFieldKind.Choice) { Span = 4 },
new(nameof(CompanyProfile.ProRataPercent), TableFieldKind.Number) { Decimals = 2, Min = 0, Max = 100, Span = 4 },
new(nameof(CompanyProfile.CashVat), TableFieldKind.Bool) { Span = 12 },
]),
]),
new("trasmittente", "send",
[
new("Transmitter", "send",
[
new(nameof(CompanyProfile.TransmitterCountry), TableFieldKind.Code) { MaxLength = 2, Span = 3 },
new(nameof(CompanyProfile.TransmitterId), TableFieldKind.Code) { MaxLength = 28, Span = 9 },
]),
new("Intermediary", "users",
[
new(nameof(CompanyProfile.IntermediaryName)) { Span = 8 },
new(nameof(CompanyProfile.IntermediaryTaxCode), TableFieldKind.Code) { MaxLength = 16, Span = 4 },
]),
]),
];
/// Every field, in order.
public static IEnumerable Fields => Tabs.SelectMany(t => t.Groups).SelectMany(g => g.Fields);
/// The tab of a field, to show the one with an error.
/// The property.
/// The tab, or .
public static ProfileTab? TabOf(string? property) =>
Tabs.FirstOrDefault(t => t.Groups.Any(g => g.Fields.Any(f => f.Property == property)));
private static CodeList? TaxRegimes(IFiscalPack pack) => pack.GetFeature()?.TaxRegimes;
}