syntax = "proto3";

package useraddress;

import "public_messages.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";
import "google/protobuf/duration.proto";  
import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";

option csharp_namespace = "CMSMicroservice.Protobuf.Protos.UserAddress";

service UserAddressContract
{
    rpc CreateNewUserAddress(CreateNewUserAddressRequest) returns (CreateNewUserAddressResponse){
        option (google.api.http) = {
            post: "/CreateNewUserAddress"
            body: "*"
        };
    };
    rpc UpdateUserAddress(UpdateUserAddressRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            put: "/UpdateUserAddress"
            body: "*"
        };
    };
    rpc DeleteUserAddress(DeleteUserAddressRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            delete: "/DeleteUserAddress"
            body: "*"
        };
    };
    rpc GetUserAddress(GetUserAddressRequest) returns (GetUserAddressResponse){
        option (google.api.http) = {
            get: "/GetUserAddress"
            
        };
    };
    rpc GetAllUserAddressByFilter(GetAllUserAddressByFilterRequest) returns (GetAllUserAddressByFilterResponse){
        option (google.api.http) = {
            get: "/GetAllUserAddressByFilter"
            
        };
    };
    rpc SetAddressAsDefault(SetAddressAsDefaultRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            post: "/SetAddressAsDefault"
            body: "*"
        };
    };
    
    // ============= Customer-specific Methods =============
    
    rpc GetCustomerAddresses(GetCustomerAddressesRequest) returns (GetCustomerAddressesResponse){
        option (google.api.http) = {
            get: "/Customer/GetAddresses"
        };
    };
    rpc CreateCustomerAddress(CreateCustomerAddressRequest) returns (CreateCustomerAddressResponse){
        option (google.api.http) = {
            post: "/Customer/CreateAddress"
            body: "*"
        };
    };
    rpc UpdateCustomerAddress(UpdateCustomerAddressRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            put: "/Customer/UpdateAddress"
            body: "*"
        };
    };
    rpc DeleteCustomerAddress(DeleteCustomerAddressRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            delete: "/Customer/DeleteAddress"
            body: "*"
        };
    };
    rpc SetCustomerDefaultAddress(SetCustomerDefaultAddressRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            post: "/Customer/SetDefaultAddress"
            body: "*"
        };
    };
}
message CreateNewUserAddressRequest
{
    int64 user_id = 1;
    string title = 2;
    string address = 3;
    string postal_code = 4;
    bool is_default = 5;
    int64 city_id = 6;
}
message CreateNewUserAddressResponse
{
    int64 id = 1;
}
message UpdateUserAddressRequest
{
    int64 id = 1;
    int64 user_id = 2;
    string title = 3;
    string address = 4;
    string postal_code = 5;
    bool is_default = 6;
    int64 city_id = 7;
}
message DeleteUserAddressRequest
{
    int64 id = 1;
}
message GetUserAddressRequest
{
    int64 id = 1;
}
message GetUserAddressResponse
{
    int64 id = 1;
    int64 user_id = 2;
    string title = 3;
    string address = 4;
    string postal_code = 5;
    bool is_default = 6;
    int64 city_id = 7;
}
message GetAllUserAddressByFilterRequest
{
    messages.PaginationState pagination_state = 1;
    google.protobuf.StringValue sort_by = 2;
    GetAllUserAddressByFilterFilter filter = 3;
}
message GetAllUserAddressByFilterFilter
{
    google.protobuf.Int64Value id = 1;
    google.protobuf.Int64Value user_id = 2;
    google.protobuf.StringValue title = 3;
    google.protobuf.StringValue address = 4;
    google.protobuf.StringValue postal_code = 5;
    google.protobuf.BoolValue is_default = 6;
    google.protobuf.Int64Value city_id = 7;
}
message GetAllUserAddressByFilterResponse
{
    messages.MetaData meta_data = 1;
    repeated GetAllUserAddressByFilterResponseModel models = 2;
}
message GetAllUserAddressByFilterResponseModel
{
    int64 id = 1;
    int64 user_id = 2;
    string title = 3;
    string address = 4;
    string postal_code = 5;
    bool is_default = 6;
    int64 city_id = 7;
}
message SetAddressAsDefaultRequest
{
    int64 id = 1;
}

// ============= Customer Messages =============

message GetCustomerAddressesRequest
{
    // user_id will be extracted from JWT token
}
message GetCustomerAddressesResponse
{
    repeated CustomerAddressModel models = 1;
}
message CustomerAddressModel
{
    int64 id = 1;
    string title = 2;
    string address = 3;
    string postal_code = 4;
    bool is_default = 5;
    int64 city_id = 6;
    string city_name = 7;
    string province_name = 8;
}
message CreateCustomerAddressRequest
{
    string title = 1;
    string address = 2;
    string postal_code = 3;
    bool is_default = 4;
    int64 city_id = 5;
    // user_id will be extracted from JWT token
}
message CreateCustomerAddressResponse
{
    int64 id = 1;
    string message = 2;
}
message UpdateCustomerAddressRequest
{
    int64 id = 1;
    string title = 2;
    string address = 3;
    string postal_code = 4;
    bool is_default = 5;
    int64 city_id = 6;
    // user_id will be extracted from JWT token
}
message DeleteCustomerAddressRequest
{
    int64 id = 1;
    // user_id will be extracted from JWT token
}
message SetCustomerDefaultAddressRequest
{
    int64 id = 1;
    // user_id will be extracted from JWT token
}
