from linter_adapters.common import BaseCategory, Severity, ViolationPrototype
from linter_adapters.parser import BaseViolationParser


class PycodestyleCategory(BaseCategory):
    Indentation = 100
    Whitespace  = 200
    BlankLines  = 300
    Imports     = 400
    LineLength  = 500
    Deprecation = 600
    Statements  = 700
    Comments    = 800   # comes from flake8-eradicate
    SyntaxError = 900


@BaseViolationParser.register_decorator('E', 'W')
class PycodestyleViolationParser(BaseViolationParser[PycodestyleCategory]):
    provider_name = 'pycodestyle'
    ViolationCategory = PycodestyleCategory
    severity_mapping = \
    {
        PycodestyleCategory.Indentation:    Severity.Error,
        PycodestyleCategory.Whitespace:     Severity.Error,
        PycodestyleCategory.BlankLines:     Severity.Convention,
        PycodestyleCategory.Imports:        Severity.Convention,
        PycodestyleCategory.LineLength:     Severity.Convention,
        PycodestyleCategory.Deprecation:    Severity.Warning,
        PycodestyleCategory.Statements:     Severity.Warning,
        PycodestyleCategory.Comments:       Severity.Error,
        PycodestyleCategory.SyntaxError:    Severity.Fatal,
    }
    default_severity = Severity.Warning
    
    def parse_violation_extras(self, violation: ViolationPrototype[PycodestyleCategory]) -> ViolationPrototype[PycodestyleCategory]:
        violation.string_id = violation.category.name if (violation.category is not None) else None
        if (violation.category == PycodestyleCategory.Comments):
            violation.provider = 'flake8-eradicate'
        return violation


__all__ = \
[
    'PycodestyleCategory',
    'PycodestyleViolationParser',
]
