# Church Models - Übersicht für Daemon-Entwicklung ## 1. ChurchOfficeType (falukant_type.church_office_type) **Schema:** `falukant_type` **Tabelle:** `church_office_type` **Zweck:** Definiert die verschiedenen Kirchenämter-Typen ```javascript { id: INTEGER (PK, auto-increment) name: STRING (z.B. "pope", "cardinal", "lay-preacher") seatsPerRegion: INTEGER (Anzahl verfügbarer Plätze pro Region) regionType: STRING (z.B. "country", "duchy", "city") hierarchyLevel: INTEGER (0-8, höhere Zahl = höhere Position) } ``` **Beziehungen:** - `hasMany` ChurchOffice (als `offices`) - `hasMany` ChurchApplication (als `applications`) - `hasMany` ChurchOfficeRequirement (als `requirements`) --- ## 2. ChurchOfficeRequirement (falukant_predefine.church_office_requirement) **Schema:** `falukant_predefine` **Tabelle:** `church_office_requirement` **Zweck:** Definiert Voraussetzungen für Kirchenämter ```javascript { id: INTEGER (PK, auto-increment) officeTypeId: INTEGER (FK -> ChurchOfficeType.id) prerequisiteOfficeTypeId: INTEGER (FK -> ChurchOfficeType.id, nullable) minTitleLevel: INTEGER (nullable, optional) } ``` **Beziehungen:** - `belongsTo` ChurchOfficeType (als `officeType`) - `belongsTo` ChurchOfficeType (als `prerequisiteOfficeType`) --- ## 3. ChurchOffice (falukant_data.church_office) **Schema:** `falukant_data` **Tabelle:** `church_office` **Zweck:** Speichert tatsächlich besetzte Kirchenämter ```javascript { id: INTEGER (PK, auto-increment) officeTypeId: INTEGER (FK -> ChurchOfficeType.id) characterId: INTEGER (FK -> FalukantCharacter.id) regionId: INTEGER (FK -> RegionData.id) supervisorId: INTEGER (FK -> FalukantCharacter.id, nullable) createdAt: DATE updatedAt: DATE } ``` **Beziehungen:** - `belongsTo` ChurchOfficeType (als `type`) - `belongsTo` FalukantCharacter (als `holder`) - `belongsTo` FalukantCharacter (als `supervisor`) - `belongsTo` RegionData (als `region`) --- ## 4. ChurchApplication (falukant_data.church_application) **Schema:** `falukant_data` **Tabelle:** `church_application` **Zweck:** Speichert Bewerbungen für Kirchenämter ```javascript { id: INTEGER (PK, auto-increment) officeTypeId: INTEGER (FK -> ChurchOfficeType.id) characterId: INTEGER (FK -> FalukantCharacter.id) regionId: INTEGER (FK -> RegionData.id) supervisorId: INTEGER (FK -> FalukantCharacter.id) status: ENUM('pending', 'approved', 'rejected') decisionDate: DATE (nullable) createdAt: DATE updatedAt: DATE } ``` **Beziehungen:** - `belongsTo` ChurchOfficeType (als `officeType`) - `belongsTo` FalukantCharacter (als `applicant`) - `belongsTo` FalukantCharacter (als `supervisor`) - `belongsTo` RegionData (als `region`) --- ## Zusätzlich benötigte Models (für Daemon) ### RegionData (falukant_data.region) - Wird für `regionId` in ChurchOffice und ChurchApplication benötigt - Enthält `regionType` (country, duchy, markgravate, shire, county, city) - Enthält `parentId` für Hierarchie ### FalukantCharacter (falukant_data.character) - Wird für `characterId` (Inhaber/Bewerber) benötigt - Wird für `supervisorId` benötigt --- ## Wichtige Queries für Daemon ### Verfügbare Positionen finden ```sql SELECT cot.*, COUNT(co.id) as occupied_seats FROM falukant_type.church_office_type cot LEFT JOIN falukant_data.church_office co ON cot.id = co.office_type_id AND co.region_id = ? WHERE cot.region_type = ? GROUP BY cot.id HAVING COUNT(co.id) < cot.seats_per_region ``` ### Supervisor finden ```sql SELECT co.* FROM falukant_data.church_office co JOIN falukant_type.church_office_type cot ON co.office_type_id = cot.id WHERE co.region_id = ? AND cot.hierarchy_level > ( SELECT hierarchy_level FROM falukant_type.church_office_type WHERE id = ? ) ORDER BY cot.hierarchy_level ASC LIMIT 1 ``` ### Voraussetzungen prüfen ```sql SELECT cor.* FROM falukant_predefine.church_office_requirement cor WHERE cor.office_type_id = ? ``` ### Bewerbungen für Supervisor ```sql SELECT ca.* FROM falukant_data.church_application ca WHERE ca.supervisor_id = ? AND ca.status = 'pending' ```