package com.elgassia.bridge.view.tui.commands.team.bidding;

import com.elgassia.bridge.Model.BidType;
import com.elgassia.bridge.exception.BridgeLogicException;
import com.elgassia.bridge.utils.Colors;
import com.elgassia.bridge.adapter.BiddingAdapter;
import com.elgassia.bridge.view.tui.Command;

public class Bid extends Command {
    private final BiddingAdapter biddingAdapter;

    public Bid(BiddingAdapter biddingAdapter) {
        this.biddingAdapter = biddingAdapter;
    }

    @Override
    public void execute() {
        try {
            if (args.length == 2) {
                switch (args[1]) {
                    case "pass":
                        biddingAdapter.bid(new com.elgassia.bridge.Model.Bid(BidType.PASS));
                        return;
                    case "contra":
                        biddingAdapter.bid(new com.elgassia.bridge.Model.Bid(BidType.CONTRA));
                        return;
                    case "recontra":
                        biddingAdapter.bid(new com.elgassia.bridge.Model.Bid(BidType.RECONTRA));
                        return;
                }
            } else if (args.length == 3) {
                Integer count = Integer.parseInt(args[1]);
                String color = args[2];
                biddingAdapter.bid(new com.elgassia.bridge.Model.Bid(BidType.CARD, count, Colors.fromString(color)));
                return;
            }
            usage();
        } catch (BridgeLogicException e) {
            System.out.println(e.getMessage());
        }
    }

    private void usage() {
        System.out.println("usage: contra | recontra | pass | <count> <color>");
    }

    @Override
    public String description() {
        return "make a bid:\n\tcontra\n\trecontra\n\tpass\n\t<count> <color>";
    }
}

@@ -96,16 +96,107 @@
 idType;%0A
+import com.elgassia.bridge.Model.Color;%0Aimport com.elgassia.bridge.adapter.BiddingAdapter;%0A
 import c
@@ -291,59 +291,8 @@
 rs;%0A
-import com.elgassia.bridge.adapter.BiddingAdapter;%0A
 impo
@@ -1252,16 +1252,17 @@
 gs%5B1%5D);%0A
+%0A
         
@@ -1273,31 +1273,190 @@
     
-String color = args%5B2%5D;
+Color color = Colors.fromString(args%5B2%5D);%0A                if (color == null) %7B%0A                    System.out.println(%22invalid color%22);%0A                    return;%0A                %7D%0A
 %0A   
@@ -1546,34 +1546,15 @@
 nt, 
-Colors.fromString(
 color))
-)
 ;%0A  

handle invalid bidding color