import Base: +, -, *, &, |, xor, ==, ~

for op in (:+, :-, :&, :|, :xor, :(==))
    @eval begin
        function ($op)(a::PyenumValues{T}, b::PyenumValues{S}) where {T<:Integer,S<:Integer}
            N = promote_type(T, S)
            ($op)(N(a.value), N(b.value))
        end
        function ($op)(a::PyenumValues{T}, b::PyenumValues{S}) where {T<:String,S<:String}
            print("convert")
            N = promote_type(T, S)
            ($op)(N(a.value), N(b.value))
        end
        function ($op)(a::PyenumValues{T}, b::S) where {T<:Integer,S<:Integer}
            N = promote_type(T, S)
            ($op)(N(a.value), N(b))
        end
        function ($op)(a::T, b::PyenumValues{S}) where {T<:Integer,S<:Integer}
            N = promote_type(T, S)
            ($op)(N(a), N(b.value))
        end
    end
end

function ~(a::PyenumValues{T}) where {T<:Integer}
    ~(T(a.value))
end

function ~(a::PyenumValues{T}) where {T<:String}
    ~(T(a.value))
end

Base.convert(::Type{T1}, x::PyenumValues{T2}) where {T1<:Integer,T2<:Integer} = convert(T1, T2(x.value))
Base.convert(::Type{T1}, x::PyenumValues{T2}) where {T1<:String,T2<:String} = convert(T1, T2(x.value))
