erDiagram

    "유저"{
        Long user_id PK
        Long combine_user_group_id FK "결합 유저 그룹 ID"
        Long locale_id FK "주소지"

        String name
        String phone_number

    }

    "장바구니"{
        Long cart_id PK
        Long user_id PK, FK
        Long product_group_id FK "상품 그룹 아이디"
        Enum group_type FK "상품 타입"
        Long product_type FK "상품 아이디"
        
        Long gift_id FK "사은품 ID"

        Long combine_discount_id FK "할인 대상 ID"
        Long onlie_discount_id FK "할인 대상 ID"
        Long agreement_discount_id FK "할인 대상 ID"
        Long non_gift_discount_id FK "할인 대상 ID"

        int fee "중간 계산 금액"
    }
    "주문" {
        Long order_id PK
        Long user_id PK, FK
        Long product_group_id FK "상품 그룹 아이디"
        Enum group_type FK "상품 타입"
        Long product_type FK "상품 아이디"        
        Long gift_id FK "사은품 아이디"
        Long combine_discount_id FK "할인 대상 ID"
        Long onlie_discount_id FK "할인 대상 ID"
        Long agreement_discount_id FK "할인 대상 ID"
        Long non_gift_discount_id FK "할인 대상 ID"
        Long locale_id FK ""
        Long equipment_history "설치 history"

        String install_company_id "설치 업체"
        Enum order_state "주문 상태"
        Enum install_state "설치 상태"
        int fee "계산 금액"
        String account "결제 토큰"

        Date order_date 
    }

    "어드민"{
        Long admin_id PK
        Long rule_id FK
    }

    "어드민 권한"{
        Long admin_id PK, FK
        Long rule_id PK, FK
    }

    "권한 당 관리 목록"{
        Long rule_id PK
        Long table "관리 테이블"
        Enum role "C, R, RU, CRU, CRUD"
    }    
    

    "컴포넌트" {
        Long component_Id PK
        Long admin_id FK "최초 생성 어드민"

        Int conponent_sequence
        Enum component_position "컴포넌트 위치"
        Date crate_date
        Date expired_date
        boolean delete_yn
    }

    "컴포넌트 히스토리" {
        Long component_Id PK, FK
        Int History_sequence PK
        Long admin_id FK "생성 어드민"

        Blob html_contents
        Date update_date
        boolean is_display
        boolean delete_yn
    }

    "상품 그룹" {
        Long product_group_id PK
        Enum group_type PK
        Long admin_id FK "등록 어드민"
        String name
        String contents "상품 소개"
        Decimal Discount_Group_Percent "결합할인 퍼센트"
        boolean used_yn
    }

    "상품 설치 장비" {
        Long product_group_id PK, FK
        Enum group_type PK, FK
        String equipment_group_product_num PK, FK
        Enum equipment_type PK, FK
        boolean isAvailable "설치 가능 여부"
    }

    "설치 장비" {
        String equipment_group_product_num PK
        Enum equipment_type PK "장비 타입"
        String name "장비 이름"
        boolean is_rental_avaiable "임대 가능 여부"
        int stock "총 재고 수"
    }

    "설치 장비 히스토리"{
        Long equipment_history PK
        Long user_id Fk
        Long district_id Fk
        String serial_num "장비 시리얼넘버"
        Enum rental_type "설치 상태"
        Enum install_state "설치 상태"
    }
    

    "TV 상품" }o.-o{"상품 설치 장비" : "설치"
    "인터넷 상품" }o.-o{"상품 설치 장비" : "설치"

    "구"}|--|{"설치 장비" : "재고 보유 수"

    "인터넷/TV 상품 그룹"{
        Long product_group_id PK
        Long internet_group_id FK
        Long tv_group_id FK
    }

    "인터넷/TV 상품"{
        Long product_group_id PK
        Long internet_id FK
        Long tv_id FK
        Long admin_id FK "등록 어드민"
        Boolean default_yn "Default 상품 여부"
        
        String internet_tv_group_name
        String contents "상품 소개"
        boolean used_yn
    }

    "인터넷 상품 그룹"{
        Long internet_group_id PK
        Enum network_gorup "5g, 4g, 3g"
    }

    "인터넷 상품"{
        Long internet_id PK
        Long internet_group_id PK, FK
        int internet_speed_id PK, FK
        Long admin_id FK "등록 어드민"

        Decimal fee "기본 요금"
        String contents "상품 소개"
        String internet_name
        boolean used_yn
    }

    "인터넷 상품 속도" {
        int internet_speed_id PK
        int internet_speed "속도"
        Boolean is_contain_wifi "와이파이 포함 여부"
        blob contents "상품 소개"
    }

    "TV 상품 그룹"{
        Long tv_group_id PK
    }

    "TV 상품"{
        Long tv_id PK
        Long tv_group_id PK, FK
        Long tv_group_channel_id PK, FK "TV 상품 채널"
        Long admin_id FK "등록 어드민"
        

        String internet_name_detail
        String contents "상품 소개"

        Decimal fee "기본 요금"
        boolean used_yn
    }

    "TV 상품 채널" {
        Long tv_group_channel_id PK
        Int Channel_count
        blob contents "상품 소개"
    }

    "할인" {
        Long discount_id PK
        Enum discount_type PK "약정, 결합, 온라인"
        Long product_group_id FK "타겟 상품 그룹"
        int discount_fee "할인($)"
    }

    "약정 할인" {
        Long discount_id PK, FK
        Long prod_id PK, FK "상품 아이디"
        Enum prod_type PK "상품 타입 (TV, Internet, TV/Internet)"
        Enum agreement_year "약정 년"
    }    

    "결합 유저 그룹" {  
        Long combine_user_group_id PK
        Long combine_user_target_id PK, FK "결합 대상 유저"
        Long combine_user_leader_id FK "결합 리더 유저"
    }

    "휴대폰 결합 할인"{
        Long combie_discount_id PK
        int combine_count PK "결합 수"
        Long product_group_id FK "그룹 아이디"
    }

    "온라인 할인"{
        Long online_discount_id PK
        Long product_group_id FK "상품 그룹"
    }

    "슬림 요금제 할인"{
        Long non_gift_discount_id 
        Long product_group_id FK "상품 그룹"
        Long gift_group_id FK "사은품 그룹"
        int discount_fee "약정 할인"
    }

    "상품 그룹 사은품"{
        Long gift_group_id PK, FK
        Long product_group_id PK, FK
    }

    "사은품 그룹" {
        Long gift_group_id PK
        Long gift_type_id FK
        String thumbnail_image "섬네일 이미지"
        blob HTML_contents ""
        boolean used_yn
    }

    "사은품" {
        Long gift_group_id PK, FK
        Long gift_id PK
        Long sequence PK
        int stock
        String option
        String color_hex
        boolean used_yn
    }

    "사은품 타입" {
        Long gift_type_id PK
        String name "타입 이름"
    }

    "지역 설치 상품 그룹" {
        Long locale_id FK
        Long product_group_id FK
    }

    "주소" {
        Long locale_id PK
        Long city_id Fk "시"
        Long country_id FK "군"
        Long district_id Fk "구"
        Long load_num "도로명 코드"
        String address_name "주소지"
    }

    "시"{
        Long city_id Fk "시"
        String city_name "주소지"
    }

    "군"{
        Long country_id FK "군"
        String country_name "주소지"
    }

    "구"{
        Long district_id Fk "구"
        String district_name "주소지"
    }

    "지역 별 구매 내역" {
        Long locale_district_id
        Long district_id Fk "구"
        Lng locale_id FK "주소 id"
        Long order_id FK "주문 id"
        Long product_group_id FK "구매 그룹"
        Enum product_type FK "구매 타입"
    }

    "지역 별 구매 내역" ||--|{ "구" : "에서" 
    "지역 별 구매 내역" ||--|{ "주소" : "에서"
    "지역 별 구매 내역" ||--|{ "주문" : "을"
    "지역 별 구매 내역" ||--|{ "상품 그룹" : "을"

    "유저" ||--o{ "결합 유저 그룹" : "결합 목록"

    "어드민" ||--|{ "어드민 권한" : "has"
    "어드민 권한" }o--|{ "권한 당 관리 목록" : "권한을 가진다"

    "어드민" ||--o{ "컴포넌트" : "등록"
    "어드민" ||--o{ "컴포넌트 히스토리" : "등록"

    "어드민" ||--o{ "상품 그룹" : "등록"
    "어드민" ||--o{ "인터넷 상품" : "등록"
    "어드민" ||--o{ "TV 상품" : "등록"

    "상품 그룹" |o--|| "인터넷/TV 상품 그룹"  : "포함"
    "상품 그룹" |o--|| "TV 상품 그룹"  : "포함"
    "상품 그룹" |o--|| "인터넷 상품 그룹"  : "포함"

    "컴포넌트" ||--|{ "컴포넌트 히스토리" : "상세"

    "인터넷/TV 상품 그룹" ||--|{ "인터넷/TV 상품" : "상세"
    "인터넷/TV 상품" ||--|{ "인터넷 상품" : "포함"
    "인터넷/TV 상품" ||--|{ "TV 상품" : "포함"
    
    "인터넷 상품 그룹" ||--|{ "인터넷 상품" : "상세"
    "인터넷 상품" ||--|{  "인터넷 상품 속도" : "상세"

    "TV 상품 그룹" ||--|{ "TV 상품" : "상세"
    "TV 상품" ||--|{  "TV 상품 채널" : "상세"

    "사은품 그룹" ||--|{ "사은품" : "상세"
    "사은품 그룹" ||--|{ "사은품 타입" : "상세"

    "상품 그룹 사은품" ||--|{ "사은품 그룹" : "포함"
    "상품 그룹 사은품" ||--|{ "상품 그룹" : "포함"

    "할인" |o..|| "약정 할인" : "sup"
    "할인" |o..|| "휴대폰 결합 할인" : "sup"
    "할인" |o..|| "온라인 할인" : "sup"

    "상품 그룹" |o--|{ "할인" : "포함"
    
    "슬림 요금제 할인" ||--|| "상품 그룹" : "포함"
    "슬림 요금제 할인" ||--|| "사은품 그룹" : "포함"

    "유저" ||--o{ "장바구니" : "담다"
    "장바구니" ||--o| "상품 그룹" : "담다"
    "장바구니" |o..o| "TV 상품" : "담다"
    "장바구니" |o..o| "인터넷/TV 상품" : "담다"
    "장바구니" |o..o| "인터넷 상품" : "담다"

    "장바구니" |o..|| "약정 할인" : "받다"
    "장바구니" |o..|| "휴대폰 결합 할인" : "받다"
    "장바구니" |o..|| "온라인 할인" : "받다"
    "장바구니" |o..|| "슬림 요금제 할인" : "받다"
    
    "주소" ||--|| "시": "구역"
    "주소" ||--|| "군": "구역"
    "주소" ||--|| "구" : "구역"

    "지역 설치 상품 그룹" ||--|| "상품 그룹" : "설치 가능"
    "지역 설치 상품 그룹" ||--|| "주소" : "설치 가능"

    "주문" |o..|| "약정 할인" : "받다"
    "주문" |o..|| "온라인 할인" : "받았다"
    "주문" |o..|| "휴대폰 결합 할인" : "받았다"
    "주문" |o..|| "슬림 요금제 할인" : "받았다"

    "주문" ||--|| "상품 그룹" : "구매하다"
    "주문" |o--|| "인터넷 상품" : "구매하다"
    "주문" |o--|| "TV 상품" : "구매하다"
    "주문" ||--|| "주소" : "설치하다"

    "주문" |o--|| "설치 장비 히스토리" : "설치하다"