1# =====================================================
2# Imports
3# =====================================================
4from typing import Annotated
5
6from pydantic import Field, field_validator
7
8from mt_metadata.base import MetadataBase
9from mt_metadata.common import Comment
10from mt_metadata.transfer_functions.io.emtfxml.metadata import helpers
11
12
13# =====================================================
14class DataQualityWarnings(MetadataBase):
15 flag: Annotated[
16 int | None,
17 Field(
18 default=None,
19 description="Flag for data quality",
20 alias=None,
21 json_schema_extra={
22 "units": None,
23 "required": False,
24 "examples": ["0"],
25 },
26 ),
27 ]
28 comments: Annotated[
29 Comment | None,
30 Field(
31 default_factory=Comment, # type: ignore
32 description="Comments about the data quality warnings",
33 alias=None,
34 json_schema_extra={
35 "units": None,
36 "required": False,
37 "examples": ["Data quality is good", "Some issues found"],
38 },
39 ),
40 ]
41
42 @field_validator("comments", mode="before")
43 @classmethod
44 def validate_comments(cls, v):
45 """Ensure comments is an instance of Comment."""
46 if isinstance(v, Comment):
47 return v
48 elif isinstance(v, str):
49 return Comment(value=v) # type: ignore
50 elif v is None:
51 return Comment() # type: ignore
52 else:
53 raise TypeError("comments must be a Comment instance or a string")
54
55 def read_dict(self, input_dict):
56 """
57
58 :param input_dict: DESCRIPTION
59 :type input_dict: TYPE
60 :return: DESCRIPTION
61 :rtype: TYPE
62
63 """
64 helpers._read_element(self, input_dict, "data_quality_warnings")
65
66 def to_xml(self, string=False, required=True):
67 """
68
69 :param string: DESCRIPTION, defaults to False
70 :type string: TYPE, optional
71 :param required: DESCRIPTION, defaults to True
72 :type required: TYPE, optional
73 :return: DESCRIPTION
74 :rtype: TYPE
75
76 """
77
78 return helpers.to_xml(
79 self,
80 string=string,
81 required=required,
82 order=["flag", "comments"],
83 )