{
  "metadata": {
    "version": "1.0",
    "description": "Legal entities field mapping configuration for CRM integration",
    "created_date": "2025-09-17",
    "use_case": "Company/legal entity data synchronization"
  },
  "source": {
    "table": "datamart.statgov_snap_legal_entities_v1_5_view_latest",
    "primary_key": "id",
    "batch_column": "id",
    "order_by": "id"
  },
  "field_mappings": {
    "id": {
      "target": null,
      "type": "integer",
      "required": false,
      "description": "Internal ID, not included in output"
    },
    "bin": {
      "target": "UF_BIN",
      "type": "string",
      "required": true,
      "validation": {
        "type": "digits_only",
        "min_length": 12,
        "max_length": 12
      },
      "description": "Business Identification Number (12 digits)"
    },
    "company_name": {
      "target": "UF_COMPANY_NAME",
      "type": "string",
      "required": true,
      "validation": {
        "min_length": 1,
        "max_length": 500
      },
      "description": "Company short name"
    },
    "full_company_name_rus": {
      "target": "UF_COMPANY_FULL_NAME",
      "type": "string",
      "required": false,
      "alias": "full_company_name_rus",
      "validation": {
        "max_length": 1000
      },
      "description": "Full company name in Russian"
    },
    "org_form": {
      "target": "UF_ORG_FORM",
      "type": "string",
      "required": false,
      "validation": {
        "max_length": 100
      },
      "description": "Organization form (ТОО, АО, ИП, etc.)"
    },
    "register_date": {
      "target": "UF_REGISTER_DATE",
      "type": "date",
      "required": false,
      "transformation": "iso_format",
      "description": "Company registration date"
    },
    "oked": {
      "target": "UF_OKED",
      "type": "string",
      "required": false,
      "validation": {
        "type": "digits_only",
        "min_length": 5,
        "max_length": 6
      },
      "description": "OKED classification code"
    },
    "main_activity_rus": {
      "target": "UF_MAIN_ACTIVITY",
      "type": "string",
      "required": false,
      "alias": "main_activity",
      "validation": {
        "max_length": 1000
      },
      "description": "Main activity description"
    },
    "second_oked": {
      "target": "UF_SECOND_OKED",
      "type": "string",
      "required": false,
      "validation": {
        "exclude_if_same_as": "oked",
        "type": "digits_only",
        "min_length": 5,
        "max_length": 6
      },
      "description": "Secondary OKED code"
    },
    "krp_code": {
      "target": "UF_KRP_CODE",
      "type": "string",
      "required": false,
      "description": "KRP classification code"
    },
    "krp_name_rus": {
      "target": "UF_KRP_NAME",
      "type": "string",
      "required": false,
      "alias": "krp_name",
      "validation": {
        "max_length": 500
      },
      "description": "KRP classification name"
    },
    "legal_address": {
      "target": "UF_ADDRESS",
      "type": "string",
      "required": false,
      "validation": {
        "max_length": 1000
      },
      "description": "Legal address"
    },
    "ceo_name": {
      "target": "UF_CEO_NAME",
      "type": "string",
      "required": false,
      "validation": {
        "max_length": 300
      },
      "description": "CEO full name"
    },
    "region": {
      "target": "UF_REGION",
      "type": "string",
      "required": false,
      "validation": {
        "max_length": 200
      },
      "description": "Region name"
    },
    "city_name_rus": {
      "target": "UF_CITY_NAME",
      "type": "string",
      "required": false,
      "alias": "city_name",
      "validation": {
        "max_length": 200
      },
      "description": "City name"
    },
    "legal_entity_type": {
      "target": "UF_COMPANYTYPE_CODE",
      "type": "string",
      "required": false,
      "validation": {
        "max_length": 50
      },
      "description": "Legal entity type code"
    },
    "legal_entity_type_txt": {
      "target": "UF_COMPANYTYPE_NAME",
      "type": "string",
      "required": false,
      "validation": {
        "max_length": 200
      },
      "description": "Legal entity type name"
    }
  },
  "transformations": {
    "date_format": "iso",
    "remove_null_values": true,
    "encoding": "utf-8",
    "exclude_empty_strings": false,
    "byte_handling": "decode_utf8"
  },
  "validation_rules": {
    "required_fields": ["UF_BIN", "UF_COMPANY_NAME"],
    "skip_record_if_missing": ["bin", "company_name"],
    "log_validation_errors": true,
    "max_validation_errors": 100
  }
}
