package info.bukova.isspst;

import info.bukova.isspst.data.Order;
import info.bukova.isspst.data.Permission;
import info.bukova.isspst.data.PermissionType;
import info.bukova.isspst.data.Requirement;
import info.bukova.isspst.data.RequirementType;
import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.TripBill;
import info.bukova.isspst.data.TripBillApproval;
import info.bukova.isspst.data.TripRequirement;
import info.bukova.isspst.reporting.Report;
import info.bukova.isspst.reporting.ReportMapping;
import info.bukova.isspst.services.addressbook.AdbService;
import info.bukova.isspst.services.buildings.BuildingService;
import info.bukova.isspst.services.fulltext.FullTextService;
import info.bukova.isspst.services.invoicing.InvoicingService;
import info.bukova.isspst.services.limits.LimitService;
import info.bukova.isspst.services.munits.MUnitService;
import info.bukova.isspst.services.orders.ApprovedService;
import info.bukova.isspst.services.orders.OrderService;
import info.bukova.isspst.services.reqsubjects.MaterialService;
import info.bukova.isspst.services.reqsubjects.ServiceItemService;
import info.bukova.isspst.services.requirement.RequirementService;
import info.bukova.isspst.services.requirement.RequirementTypeService;
import info.bukova.isspst.services.requirement.TripRequirementService;
import info.bukova.isspst.services.signeddocs.SignedDocumentService;
import info.bukova.isspst.services.tripbill.TripBillService;
import info.bukova.isspst.services.users.RoleService;
import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Constants {

	public final static long DB_VERSION = 6;

	public final static String DEF_ADMIN = "admin";
	public final static String DEF_ADMIN_PASSWD = "admin";
	public final static String ROLE_USER = "ROLE_USER";
	public final static String ROLE_ADMIN = "ROLE_ADMIN";
	public final static String ROLE_DIRECTOR = "ROLE_DIRECTOR";
	public final static String ROLE_MANAGER = "ROLE_MANAGER";
	public final static String ROLE_PRINCIPAL = "ROLE_PRINCIPAL";
	public final static String ROLE_ACCOUNTANT = "ROLE_ACCOUNTANT";
	public final static String ROLE_SUPPLIER = "ROLE_SUPPLIER";
	public final static String ROLE_TECHNICIAN = "ROLE_TECHNICIAN";
	public final static String ROLE_LEADER = "ROLE_LEADER";
	public final static Role ROLES[] = {
		new Role(ROLE_ADMIN, "Administrátor"),
		new Role(ROLE_DIRECTOR, "Ředitel"),
		new Role(ROLE_MANAGER, "Správce"),
		new Role(ROLE_PRINCIPAL, "Příkazce"),
		new Role(ROLE_ACCOUNTANT, "Účetní"),
		new Role(ROLE_SUPPLIER, "Zásobovač"),
		new Role(ROLE_TECHNICIAN, "Technik"),
		new Role(ROLE_LEADER, "Vedoucí"),
		new Role(ROLE_USER, "Uživatel")
	};
	
	public final static String PERM_READ = "PERM_READ";
	public final static String PERM_ADD = "PERM_ADD";
	public final static String PERM_EDIT = "PERM_EDIT";
	public final static String PERM_DELETE = "PERM_DELETE";
	public final static Permission DEF_PERMISSIONS[] = {
		new Permission(PERM_READ, "Číst"),
		new Permission(PERM_ADD, "Přidávat"),
		new Permission(PERM_EDIT, "Upravit"),
		new Permission(PERM_DELETE, "Mazat")
	};
	
	public final static String MOD_USERS = "USERS";
	public final static String MOD_PERMISSIONS = "PERMISSIONS";
	public final static String MOD_ADDRESSBOOK = "ADDRESSBOOK";
	public final static String MOD_BUILDINGS = "BUILDINGS";
	public final static String MOD_MUNITS = "MUNITS";
	public final static String MOD_MATERIAL = "MATERIAL";
	public final static String MOD_SERVICES = "SERVICES";
	public final static String MOD_WORKGROUPS = "WORKGROUPS";
	public final static String MOD_REQUIREMENTS = "REQUIREMENTS";
	public final static String MOD_TRIPREQUIREMENTS = "TRIPREQUIREMENTS";
	public final static String MOD_WORKFLOW = "WORKFLOW";
	public final static String MOD_TRIPBILL = "TRIPBILL";
	public final static String MOD_APPROVED = "APPROVED";
	public final static String MOD_ORDER = "ORDER";
	public final static String MOD_INVOICING = "INVOICING";
	public final static String MOD_SEARCH = "SEARCH";
	public final static String MOD_SIGNEDDOCS = "SIGNEDDOCS";
	public final static String MOD_LIMITS = "LIMITS";
	public final static Module MODULES[] = {
			new Module(MOD_USERS, "Uživatelé", UserService.class),
			new Module(MOD_PERMISSIONS, "Práva", RoleService.class),
			new Module(MOD_ADDRESSBOOK, "Dodavatelé", AdbService.class),
			new Module(MOD_BUILDINGS, "Budovy", BuildingService.class),
			new Module(MOD_MUNITS, "Měrné jednotky", MUnitService.class),
			new Module(MOD_MATERIAL, "Materiál", MaterialService.class),
			new Module(MOD_SERVICES, "Služby", ServiceItemService.class),
			new Module(MOD_WORKGROUPS, "Pracovní skupiny", WorkgroupService.class),
			new Module(MOD_REQUIREMENTS, "Požadavky na nákupy", RequirementService.class),
			new Module(MOD_TRIPREQUIREMENTS, "Požadavky na služební cesty", TripRequirementService.class),
			new Module(MOD_WORKFLOW, "Procesy schválení", RequirementTypeService.class),
			new Module(MOD_TRIPBILL, "Cestovní příkazy", TripBillService.class),
			new Module(MOD_APPROVED, "Schválené položky požadavků", ApprovedService.class),
			new Module(MOD_ORDER, "Objednávky", OrderService.class),
			new Module(MOD_INVOICING, "Fakturace požadavků", InvoicingService.class),
			new Module(MOD_SEARCH, "Fulltextové vyhledávání", FullTextService.class, true, false), 
			new Module(MOD_SIGNEDDOCS, "Podepsané dokumenty", SignedDocumentService.class, true, false),
			new Module(MOD_LIMITS, "Limity komisi", LimitService.class),
		};
	
	public final static String PERM_APPROVE = "PERM_APPROVE";
	public final static String PERM_SHOW_WORKGROUP_REQ = "PERM_SHOW_WORKGROUP_REQ";
	public final static String PERM_SHOW_CENTRE_REQ = "PERM_SHOW_CENTRE_REQ";
	public final static String PERM_SHOW_ALL_REQ = "PERM_SHOW_ALL_REQ";
	public final static String PERM_EDIT_NEW = "PERM_EDIT_NEW";
	public final static String PERM_EDIT_OWN = "PERM_EDIT_OWN";
	public final static String PERM_DELETE_NEW = "PERM_DELETE_NEW";
	public final static String PERM_SEARCH = "PERM_SEARCH";
	public final static String PERM_PAY_BILL = "PERM_PAY_BILL";
	
	public final static Permission SPECIAL_PERMISSIONS[] = {
		new Permission(PERM_EDIT_NEW, "Upravit neschválené", MOD_REQUIREMENTS, PermissionType.GLOBAL),
		new Permission(PERM_DELETE_NEW, "Mazat neschválené", MOD_REQUIREMENTS, PermissionType.GLOBAL),
		new Permission(PERM_SHOW_WORKGROUP_REQ, "Zobrazení požadavků komise", MOD_REQUIREMENTS, PermissionType.WORKGROUP),
		new Permission(PERM_SHOW_CENTRE_REQ, "Zobrazení požadavků střediska", MOD_REQUIREMENTS, PermissionType.CENTRE),
		new Permission(PERM_SHOW_ALL_REQ, "Zobrazení všech požadavků", MOD_REQUIREMENTS, PermissionType.GLOBAL),
		new Permission(PERM_APPROVE, "Schválení", MOD_REQUIREMENTS, PermissionType.WORKGROUP),
		
		new Permission(PERM_EDIT_NEW, "Upravit neschválené", MOD_TRIPREQUIREMENTS, PermissionType.GLOBAL),
		new Permission(PERM_DELETE_NEW, "Mazat neschválené", MOD_TRIPREQUIREMENTS, PermissionType.GLOBAL),
		new Permission(PERM_SHOW_WORKGROUP_REQ, "Zobrazení požadavků komise", MOD_TRIPREQUIREMENTS, PermissionType.WORKGROUP),
		new Permission(PERM_SHOW_CENTRE_REQ, "Zobrazení požadavků střediska", MOD_TRIPREQUIREMENTS, PermissionType.CENTRE),
		new Permission(PERM_SHOW_ALL_REQ, "Zobrazení všech požadavků", MOD_TRIPREQUIREMENTS, PermissionType.GLOBAL),
		new Permission(PERM_APPROVE, "Schválení", MOD_TRIPREQUIREMENTS, PermissionType.WORKGROUP),
		
		new Permission(PERM_SEARCH, "Vyhledávat", MOD_SEARCH, PermissionType.GLOBAL),
		new Permission(PERM_READ, "Číst", MOD_SIGNEDDOCS, PermissionType.GLOBAL),

		new Permission(PERM_PAY_BILL, "Vyplacení SC", MOD_TRIPBILL, PermissionType.GLOBAL)
	};
	
	public final static String DYNAMIC_REPORT_NAME = "Tabulková sestava";
	public final static ReportMapping REPORTS[] = {
			new ReportMapping(MOD_ADDRESSBOOK, new Report(1, false, "Adresní karty", "address")),
			new ReportMapping(MOD_ADDRESSBOOK, new Report(2, false, "Adresa", "address", false, true)),
			new ReportMapping(MOD_TRIPBILL, new Report(7, true, "Žádost o SC", "tripRequirementApp", false, true, "requirement")),
			new ReportMapping(MOD_TRIPBILL, new Report(4, true, "Vyúčtování", "tripBill", false, true, true)),
			new ReportMapping(MOD_ORDER, new Report(5, false, "Objednávka", "order", true, true)),
			new ReportMapping(MOD_REQUIREMENTS, new Report(6, false, "Požadavky", "requirements")),
			new ReportMapping(MOD_TRIPREQUIREMENTS, new Report(7, true, "Žádost o SC", "tripRequirementApp", false, true)),
			new ReportMapping(MOD_REQUIREMENTS, new Report(8, true, "Protokol o kontrole", "orderRequirement", false, true)),
			new ReportMapping(MOD_INVOICING, new Report(9, false, "Přehled o protokolech předběžné kontroly", "requirementProtocol")),
			new ReportMapping(MOD_TRIPREQUIREMENTS, new Report(10, true, "Přehled o protokolech předběžné kontroly", "tripRequirementProtocol"))
	};

	// pokud je v agnde vic nez jedena podepisovaci sestava, musi se definovat ktera sestava nalezi jake entite
	public final static Map<Class<?>, Integer> SIGN_REPORT_MAP = Collections.unmodifiableMap(new HashMap<Class<?>, Integer>() {{
		put(TripBillApproval.class, 4);
		put(TripRequirement.class, 7);
	}});

	// vychozi prefixy ciselnych rad. Pokud se prida agenda s vlastni ciselnou radou, je potreba zadefinovat vychozi prefix
	public final static Map<String, String> NUM_SERIES_PREFIX = Collections.unmodifiableMap(new HashMap<String, String>() {{
		put(MOD_REQUIREMENTS, "P");
		put(MOD_ORDER, "O");
	}});
	
	public final static String REQTYPE_ORDER = "ORDER";
	public final static String REQTYPE_BUSINESSTRIP = "BUSINESSTRIP";
	public final static RequirementType REQTYPES[] = {
		new RequirementType(REQTYPE_ORDER, "Objednávky materiálu a služeb"),
		new RequirementType(REQTYPE_BUSINESSTRIP, "Služební cesty")
	};

	public final static long REQ_TYPE_MATERIAL = 1;
	public final static long REQ_TYPE_SERVICES = 2;
	
	@SuppressWarnings("serial")
	public final static Map<Class<?>, String> URL_MAP = Collections.unmodifiableMap(new HashMap<Class<?>, String>() {{
		put(Requirement.class, "/main/orders/");
		put(TripRequirement.class, "/main/trips/requirements/");
		put(TripBillApproval.class, "/main/trips/bill/");
		put(Order.class, "/main/orders/created/");
		put(TripBill.class, "/main/trips/bill/");
	}} );

	public final static int LEN_TEXT = 255;
	public final static int LEN_DESCRIPTION = 8192;
	public final static int LEN_RESULT_MESSAGE = 8192;
	
	public final static String MAIL_URL_KEYWORD = "-url-";

	public final static String KEY_SIGN_DATA = "SIGN_DATA";
	public final static String KEY_SIGN_GUID = "SIGN_GUID";
}
