from typing import List
from dataclasses import dataclass, field

import cim.data_profile as cim

def get_all_attributes(feeder_id: str, mrid_list: List[str]):
    query_message = """
        PREFIX r:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
        PREFIX cim:  <http://iec.ch/TC57/CIM100#>
        SELECT ?mRID ?name ?Location ?vectorGroup
        (group_concat(distinct ?PowerTransformerEnd; separator=";") as ?PowerTransformerEnd) 
        (group_concat(distinct ?TransformerTank; separator=';') as ?TransformerTanks)
        WHERE {          
          ?eq r:type cim:PowerTransformer.
          VALUES ?fdrid {"%s"}
          VALUES ?mRID {"""%feeder_id
    # add all equipment mRID
    for mrid in mrid_list:
        query_message += ' "%s" \n'%mrid
    # add all attributes
    query_message += """               } 
        ?eq cim:Equipment.EquipmentContainer ?fdr.
        ?fdr cim:IdentifiedObject.mRID ?fdrid.

        ?eq cim:IdentifiedObject.mRID ?mRID.
        ?eq cim:IdentifiedObject.name ?name.

        OPTIONAL {?eq cim:PowerSystemResource.Location ?loc.
        ?loc cim:IdentifiedObject.mRID ?Location.}

        OPTIONAL {?eq cim:PowerTransformer.vectorGroup ?vectorGroup.}

        OPTIONAL {?tank cim:TransformerTank.PowerTransformer ?eq.
                  ?tank cim:IdentifiedObject.mRID ?TransformerTank.}

        OPTIONAL {?end cim:PowerTransformerEnd.PowerTransformer ?eq.
                  ?end cim:IdentifiedObject.mRID ?PowerTransformerEnd.}
        }
        GROUP by ?mRID ?name ?Location ?vectorGroup
        ORDER by ?name
        """
    return query_message