# People - Legal entities

# Events

--- LEGAL_ENTITY_CREATED ---
{
   "event": "LEGAL_ENTITY_CREATED",
   "data": {
         "legal_entity_id": 123,
         "person_id": 999
   }
}
--- LEGAL_ENTITY_UPDATED ---
{
    "event": "LEGAL_ENTITY_UPDATED",
    "data": {
          "legal_entity_id": 123,
          "person_id": 999
    }
}
--- LEGAL_ENTITY_DELETED ---
{
    "event": "LEGAL_ENTITY_DELETED",
    "data": {
        "legal_entity_id": 123,
        "person_id": 999
    }
}

Note: if a legal entity is updated to change the person it is linked to, there will not be a legal_entity_deleted event for that person, only a legal_entity_updated event with the legal entity id and the new person id.

# Validation

{
  "name": [
    "required",
    "max:255"
  ],
  "type": [
    "required",
    "in: legal, natural"
  ],
  "nationality_id": [
    "required",
    "valid country id",
  ],
  "address": [
    "required",
    "valid address"
  ],
  "iban": [
    "required",
    "a valid iban" // according to http://www.ibanbic.be/IBANBIC.asmx/controleIBAN?iban={VALUE}
  ],
  "bic": [
    "required if belgian iban", // can be validated and extracted using http://www.ibanbic.be/IBANBIC.asmx/BBANtoIBANandBIC?Value={VALUE}
  ],
  "legal_form": [
    "required when type == legal",
    "not relevant when type == natural",
    {
        "rule": "in",
        "values": [
             "VZW / ASBL",
             "BVBA / SPRL",
             "CBVBA / SCRL",
             "EBVBA / SPRLU",
             "CVOA / SCRI",
             "Eenmanszaak / Pers. Physique",
             "Feitelijke vereniging / Ass. De Fait",
             "NV / SA",
             "Vennootschap / Société",
             "VOF / SNC",
             "SCA",
             "SCS",
             "MTSCHP",
             "COMMV"
       ],
    }
  ],
  "vat_number" : [
    "required when type == legal",
    "must be null when type == natural",
  ],
  "national_register_number": [
    "required when type == natural",
  ]
}

# List

--- ENDPOINT ---

Domain: equidata 
Url: /people/123/legal-entities
Method: GET

--- EXAMPLE RESPONSE ---
[
    {
        "id": 987, 
        "name": "Professional Athlete BVBA",
        "type": "natural",
        "nationality": {
            "id": 123,
            "name": "Belgium",
            "iso_2": "BE",
            "iso_3": "BEL"
        },
        
        "address": {}, // an address entity
        "iban": "some-iban",
        "bic": "some-bic",
        
        // in case natural
        "national_register_number": "",
        
        // in case legal
        "legal_form": "BVBA",
        "vat_number": "BE123456789"            
    }
    // ...other legal entities
]

# Show

--- ENDPOINT ---

Domain: equidata 
Url: /people/123/legal-entities/987
Method: GET

--- EXAMPLE RESPONSE ---
{
    "id": 987, 
    "name": "Professional Athlete BVBA",
    "type": "natural",
    "nationality": {
        "id": 123,
        "name": "Belgium",
        "iso_2": "BE",
        "iso_3": "BEL"
    },
    
    "address": {}, // an address entity
    "iban": "some-iban",
    "bic": "some-bic",
    
    // in case natural
    "national_register_number": "",
    
    // in case legal
    "legal_form": "BVBA",
    "vat_number": "BE123456789"            
}

# Create

--- ENDPOINT ---

Domain: equidata 
Url: /people/123/legal-entities
Method: POST

--- EXAMPLE PAYLOAD ---
{
    // always
    "name": "Professional Athlete BVBA",
    "type": "natural",
    "nationality_id": 123,
    
    "address": {}, // an address entity
    
    "iban": "some-iban",
    "bic": "some-bic",
    
    // in case natural
    "national_register_number": "",
    
    // in case legal
    "legal_form": "BVBA",
    "vat_number": "BE123456789"
    
}
--- EXAMPLE RESPONSE ---
{
    // always
    "id": 987,
    "name": "Professional Athlete BVBA",
    "type": "natural",
    "nationality": {
        "id": 123,
        "name": "Belgium",
        "iso_2": "BE",
        "iso_3": "BEL"
    },
    
    "address": {}, // an address entity
    
    "iban": "some-iban",
    "bic": "some-bic",
    
    // in case natural
    "national_register_number": "",
    
    // in case legal
    "legal_form": "BVBA",
    "vat_number": "BE123456789"
    
}

# Update

--- ENDPOINT ---

Domain: equidata 
Url: /people/123/legal-entities/987
Method: PUT

--- EXAMPLE PAYLOAD ---
{
    // always
    "name": "Professional Athlete BVBA",
    "type": "natural",
    "nationality_id": 123,
    
    "address": {}, // an address entity
    
    "iban": "some-iban",
    "bic": "some-bic",
    
    // in case natural
    "national_register_number": "",
    
    // in case legal
    "legal_form": "BVBA",
    "vat_number": "BE123456789"
    
}
--- EXAMPLE RESPONSE ---
{
    // always
    "id": 987,
    "name": "Professional Athlete BVBA",
    "type": "natural",
    "nationality": {
        "id": 123,
        "name": "Belgium",
        "iso_2": "BE",
        "iso_3": "BEL"
    },
    
    "address": {}, // an address entity
    
    "iban": "some-iban",
    "bic": "some-bic",
    
    // in case natural
    "national_register_number": "",
    
    // in case legal
    "legal_form": "BVBA",
    "vat_number": "BE123456789"
    
}

# Delete

--- ENDPOINT ---

Domain: equidata 
Url: /people/123/legal-entities/987
Method: DELETE

--- EXAMPLE RESPONSE ---
// empty, simply a HTTP 200 status code